コード例 #1
0
        private IDocumentPeekResult CreateResult()
        {
            var tokenLine  = _token.GetLine();
            var lineNumber = tokenLine.LineNumber;

            const int startLineIndex = 0;
            var       endLineIndex   = tokenLine.LineEnd;
            var       idIndex        = _token.GetStart() - tokenLine.LineStart;
            var       path           = _token.Document.Path;

            var displayInfo = new PeekResultDisplayInfo(
                label: path,
                labelTooltip: path,
                title: path,
                titleTooltip: path);

            return(_peekResultFactory.Create(
                       displayInfo,
                       path,
                       lineNumber,
                       startLineIndex,
                       lineNumber,
                       endLineIndex,
                       idLine: lineNumber,
                       idIndex: idIndex
                       ));
        }
コード例 #2
0
ファイル: IdPeekResultSource.cs プロジェクト: waodng/VSIX
        public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback)
        {
            if (relationshipName != PredefinedPeekRelationships.Definitions.Name)
            {
                return;
            }

            RuleSet rule;
            string  file = FindRuleSetInFile(new[] { ".less", ".scss", ".css" }, peekableItem._id, out rule);

            if (rule == null)
            {
                callback.ReportProgress(1);
                return;
            }

            using (var displayInfo = new PeekResultDisplayInfo(label: peekableItem._id, labelTooltip: file, title: Path.GetFileName(file), titleTooltip: file))
            {
                var result = peekableItem._peekResultFactory.Create
                             (
                    displayInfo,
                    file,
                    new Span(rule.Start, rule.Length),
                    rule.Start,
                    false
                             );

                resultCollection.Add(result);
                callback.ReportProgress(1);
            }
        }
コード例 #3
0
        public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback)
        {
            if (relationshipName != PredefinedPeekRelationships.Definitions.Name)
            {
                return;
            }

            RuleSet rule;
            string file = FindRuleSetInFile(new[] { ".less", ".scss", ".css" }, peekableItem._className, out rule);

            if (rule == null)
            {
                callback.ReportProgress(1);
                return;
            }

            using (var displayInfo = new PeekResultDisplayInfo(label: peekableItem._className, labelTooltip: file, title: Path.GetFileName(file), titleTooltip: file))
            {
                var result = peekableItem._peekResultFactory.Create
                (
                    displayInfo,
                    file,
                    new Span(rule.Start, rule.Length),
                    rule.Start,
                    false
                );

                resultCollection.Add(result);
                callback.ReportProgress(1);
            }
        }
コード例 #4
0
        internal static IDocumentPeekResult CreateDocumentPeekResult(
            string filePath,
            LinePositionSpan identifierLocation,
            LinePositionSpan entityOfInterestSpan,
            IPeekResultFactory peekResultFactory
            )
        {
            var fileName = Path.GetFileName(filePath);
            var label    = string.Format(
                "{0} - ({1}, {2})",
                fileName,
                identifierLocation.Start.Line + 1,
                identifierLocation.Start.Character + 1
                );

            var displayInfo = new PeekResultDisplayInfo(
                label: label,
                labelTooltip: filePath,
                title: fileName,
                titleTooltip: filePath
                );

            return(CreateDocumentPeekResult(
                       filePath,
                       identifierLocation,
                       entityOfInterestSpan,
                       displayInfo,
                       peekResultFactory,
                       isReadOnly: false
                       ));
        }
コード例 #5
0
        private async Task<IDocumentPeekResult> FindFunctionAsync(string sourceFileName, Span sourceSpan, string functionName) {
            try {
                string code = await GetFunctionCode(functionName);
                if (!string.IsNullOrEmpty(code)) {
                    string tempFile = Path.ChangeExtension(Path.GetTempFileName(), ".r");
                    using (var sw = new StreamWriter(tempFile)) {
                        sw.Write(code);
                    }

                    using (var displayInfo = new PeekResultDisplayInfo(
                        label: functionName, labelTooltip: functionName,
                        title: functionName, titleTooltip: functionName)) {

                        _result = _peekItem.PeekResultFactory.Create(displayInfo, tempFile, new Span(0, 0), 0, isReadOnly: true);

                        // Editor opens external items as plain text. When file opens, change content type to R.
                        IdleTimeAction.Create(() => {
                            if (_result.Span.IsDocumentOpen) {
                                var rs = _shell.ExportProvider.GetExportedValue<IContentTypeRegistryService>();
                                var ct = rs.GetContentType(RContentTypeDefinition.ContentType);
                                _result.Span.Document.TextBuffer.ChangeContentType(ct, this.GetType());
                                try { File.Delete(tempFile); } catch (IOException) { } catch (UnauthorizedAccessException) { }
                            }
                        }, 50, GetType(), _shell);

                        return _result;
                    }
                }
            } catch (Exception ex) {
                _exception = ex;
            }
            return null;
        }
コード例 #6
0
        public void FindResults(string relationshipName,
                                IPeekResultCollection resultCollection,
                                CancellationToken cancellationToken,
                                IFindPeekResultsCallback callback) {
            if (relationshipName == PredefinedPeekRelationships.Definitions.Name) {

                using (var displayInfo = new PeekResultDisplayInfo(
                    label: _peekItem.DisplayName,
                    labelTooltip: _peekItem.FileName,
                    title: Path.GetFileName(_peekItem.FileName),
                    titleTooltip: _peekItem.FileName)) {
                    var result = _peekItem.PeekResultFactory.Create
                    (
                        displayInfo,
                        _peekItem.FileName,
                        new Span(_peekItem.DefinitionNode.Start, _peekItem.DefinitionNode.Length),
                        _peekItem.DefinitionNode.Start,
                        false
                    );

                    resultCollection.Add(result);
                    callback.ReportProgress(1);
                }
            }
        }
コード例 #7
0
ファイル: PeekResultSource.cs プロジェクト: nomada2/RTVS
        public void FindResults(string relationshipName,
                                IPeekResultCollection resultCollection,
                                CancellationToken cancellationToken,
                                IFindPeekResultsCallback callback)
        {
            if (relationshipName == PredefinedPeekRelationships.Definitions.Name)
            {
                using (var displayInfo = new PeekResultDisplayInfo(
                           label: _peekItem.DisplayName,
                           labelTooltip: _peekItem.FileName,
                           title: Path.GetFileName(_peekItem.FileName),
                           titleTooltip: _peekItem.FileName)) {
                    var result = _peekItem.PeekResultFactory.Create
                                 (
                        displayInfo,
                        _peekItem.FileName,
                        new Span(_peekItem.DefinitionNode.Start, _peekItem.DefinitionNode.Length),
                        _peekItem.DefinitionNode.Start,
                        false
                                 );

                    resultCollection.Add(result);
                    callback.ReportProgress(1);
                }
            }
        }
コード例 #8
0
        public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback)
        {
            if (relationshipName != PredefinedPeekRelationships.Definitions.Name)
                return;

            var file = @"M:\Coding\Applications\DanTup.DartVS\DanTup.DartVS.Vsix\LICENCE.txt";
            using (var displayInfo = new PeekResultDisplayInfo("Danny Label", file, "My Title", file))
            {
                var result = peekableItem.peekResultFactory.Create(displayInfo, file, new Span(10, 10), 10, false);
                resultCollection.Add(result);
                callback.ReportProgress(1);
            }
        }
コード例 #9
0
ファイル: PeekHelpers.cs プロジェクト: CAPCHIK/roslyn
 internal static IDocumentPeekResult CreateDocumentPeekResult(string filePath, LinePositionSpan identifierLocation, LinePositionSpan entityOfInterestSpan, PeekResultDisplayInfo displayInfo, IPeekResultFactory peekResultFactory, bool isReadOnly)
 {
     return peekResultFactory.Create(
         displayInfo,
         filePath: filePath,
         startLine: entityOfInterestSpan.Start.Line,
         startIndex: entityOfInterestSpan.Start.Character,
         endLine: entityOfInterestSpan.End.Line,
         endIndex: entityOfInterestSpan.End.Character,
         idLine: identifierLocation.Start.Line,
         idIndex: identifierLocation.Start.Character,
         isReadOnly: isReadOnly);
 }
コード例 #10
0
ファイル: PeekHelpers.cs プロジェクト: CAPCHIK/roslyn
        internal static IDocumentPeekResult CreateDocumentPeekResult(string filePath, LinePositionSpan identifierLocation, LinePositionSpan entityOfInterestSpan, IPeekResultFactory peekResultFactory)
        {
            var fileName = Path.GetFileName(filePath);
            var label = string.Format("{0} - ({1}, {2})", fileName, identifierLocation.Start.Line + 1, identifierLocation.Start.Character + 1);

            var displayInfo = new PeekResultDisplayInfo(label: label, labelTooltip: filePath, title: fileName, titleTooltip: filePath);

            return CreateDocumentPeekResult(
                filePath,
                identifierLocation,
                entityOfInterestSpan,
                displayInfo,
                peekResultFactory,
                isReadOnly: false);
        }
コード例 #11
0
        public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback)
        {
            if (relationshipName != PredefinedPeekRelationships.Definitions.Name)
            {
                return;
            }

            var file = @"M:\Coding\Applications\DanTup.DartVS\DanTup.DartVS.Vsix\LICENCE.txt";

            using (var displayInfo = new PeekResultDisplayInfo("Danny Label", file, "My Title", file))
            {
                var result = peekableItem.peekResultFactory.Create(displayInfo, file, new Span(10, 10), 10, false);
                resultCollection.Add(result);
                callback.ReportProgress(1);
            }
        }
コード例 #12
0
            public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback)
            {
                if (relationshipName != PredefinedPeekRelationships.Definitions.Name)
                {
                    return;
                }

                // Note: this is called on a background thread, but we must block the thread since the API doesn't support proper asynchrony.
                var workspace   = _peekableItem._workspace;
                var solution    = workspace.CurrentSolution;
                var project     = solution.GetProject(_peekableItem._projectId);
                var compilation = project.GetCompilationAsync(cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken);

                var symbol = _peekableItem._symbolKey.Resolve(compilation, ignoreAssemblyKey: true, cancellationToken: cancellationToken).Symbol;

                if (symbol == null)
                {
                    callback.ReportFailure(new Exception(EditorFeaturesResources.No_information_found));
                    return;
                }

                var sourceLocations = symbol.Locations.Where(l => l.IsInSource).ToList();

                if (!sourceLocations.Any())
                {
                    // It's a symbol from metadata, so we want to go produce it from metadata
                    var options              = _peekableItem._globalOptions.GetMetadataAsSourceOptions();
                    var declarationFile      = _peekableItem._metadataAsSourceFileService.GetGeneratedFileAsync(project, symbol, signaturesOnly: true, options, cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken);
                    var peekDisplayInfo      = new PeekResultDisplayInfo(declarationFile.DocumentTitle, declarationFile.DocumentTitle, declarationFile.DocumentTitle, declarationFile.DocumentTitle);
                    var identifierSpan       = declarationFile.IdentifierLocation.GetLineSpan().Span;
                    var entityOfInterestSpan = PeekHelpers.GetEntityOfInterestSpan(symbol, workspace, declarationFile.IdentifierLocation, cancellationToken);
                    resultCollection.Add(PeekHelpers.CreateDocumentPeekResult(declarationFile.FilePath, identifierSpan, entityOfInterestSpan, peekDisplayInfo, _peekableItem.PeekResultFactory, isReadOnly: true));
                }

                var processedSourceLocations = 0;

                foreach (var declaration in sourceLocations)
                {
                    var declarationLocation = declaration.GetMappedLineSpan();

                    var entityOfInterestSpan = PeekHelpers.GetEntityOfInterestSpan(symbol, workspace, declaration, cancellationToken);
                    resultCollection.Add(PeekHelpers.CreateDocumentPeekResult(declarationLocation.Path, declarationLocation.Span, entityOfInterestSpan, _peekableItem.PeekResultFactory));
                    callback.ReportProgress(100 * ++processedSourceLocations / sourceLocations.Count);
                }
            }
コード例 #13
0
            public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback)
            {
                if (relationshipName != PredefinedPeekRelationships.Definitions.Name)
                {
                    return;
                }

                // Note: this is called on a background thread, but we must block the thread since the API doesn't support proper asynchrony.
                var workspace = _peekableItem._workspace;
                var solution = workspace.CurrentSolution;
                var project = solution.GetProject(_peekableItem._projectId);
                var compilation = project.GetCompilationAsync(cancellationToken).WaitAndGetResult(cancellationToken);

                var symbol = _peekableItem._symbolKey.Resolve(compilation, ignoreAssemblyKey: true, cancellationToken: cancellationToken).Symbol;
                if (symbol == null)
                {
                    callback.ReportFailure(new Exception(EditorFeaturesResources.No_information_found));
                    return;
                }

                var sourceLocations = symbol.Locations.Where(l => l.IsInSource).ToList();

                if (!sourceLocations.Any())
                {
                    // It's a symbol from metadata, so we want to go produce it from metadata
                    var declarationFile = _peekableItem._metadataAsSourceFileService.GetGeneratedFileAsync(project, symbol, cancellationToken).WaitAndGetResult(cancellationToken);
                    var peekDisplayInfo = new PeekResultDisplayInfo(declarationFile.DocumentTitle, declarationFile.DocumentTitle, declarationFile.DocumentTitle, declarationFile.DocumentTitle);
                    var identifierSpan = declarationFile.IdentifierLocation.GetLineSpan().Span;
                    var entityOfInterestSpan = PeekHelpers.GetEntityOfInterestSpan(symbol, workspace, declarationFile.IdentifierLocation, cancellationToken);
                    resultCollection.Add(PeekHelpers.CreateDocumentPeekResult(declarationFile.FilePath, identifierSpan, entityOfInterestSpan, peekDisplayInfo, _peekableItem.PeekResultFactory, isReadOnly: true));
                }

                int processedSourceLocations = 0;

                foreach (var declaration in sourceLocations)
                {
                    var declarationLocation = declaration.GetLineSpan();

                    var entityOfInterestSpan = PeekHelpers.GetEntityOfInterestSpan(symbol, workspace, declaration, cancellationToken);
                    resultCollection.Add(PeekHelpers.CreateDocumentPeekResult(declarationLocation.Path, declarationLocation.Span, entityOfInterestSpan, _peekableItem.PeekResultFactory));
                    callback.ReportProgress(100 * ++processedSourceLocations / sourceLocations.Count);
                }
            }
コード例 #14
0
 internal static IDocumentPeekResult CreateDocumentPeekResult(
     string filePath,
     LinePositionSpan identifierLocation,
     LinePositionSpan entityOfInterestSpan,
     PeekResultDisplayInfo displayInfo,
     IPeekResultFactory peekResultFactory,
     bool isReadOnly
     )
 {
     return(peekResultFactory.Create(
                displayInfo,
                filePath: filePath,
                startLine: entityOfInterestSpan.Start.Line,
                startIndex: entityOfInterestSpan.Start.Character,
                endLine: entityOfInterestSpan.End.Line,
                endIndex: entityOfInterestSpan.End.Character,
                idLine: identifierLocation.Start.Line,
                idIndex: identifierLocation.Start.Character,
                isReadOnly: isReadOnly
                ));
 }
コード例 #15
0
        private async Task <IDocumentPeekResult> FindFunctionAsync(string sourceFileName, Span sourceSpan, string functionName)
        {
            try {
                string code = await GetFunctionCode(functionName);

                if (!string.IsNullOrEmpty(code))
                {
                    string tempFile = Path.ChangeExtension(Path.GetTempFileName(), ".r");
                    using (var sw = new StreamWriter(tempFile)) {
                        sw.Write(code);
                    }

                    using (var displayInfo = new PeekResultDisplayInfo(
                               label: functionName, labelTooltip: functionName,
                               title: functionName, titleTooltip: functionName)) {
                        _result = _peekItem.PeekResultFactory.Create(displayInfo, tempFile, new Span(0, 0), 0, isReadOnly: true);

                        // Editor opens external items as plain text. When file opens, change content type to R.
                        IdleTimeAction.Create(() => {
                            if (_result.Span.IsDocumentOpen)
                            {
                                var rs = _services.GetService <IContentTypeRegistryService>();
                                var ct = rs.GetContentType(RContentTypeDefinition.ContentType);
                                _result.Span.Document.TextBuffer.ChangeContentType(ct, this.GetType());
                                try { File.Delete(tempFile); } catch (IOException) { } catch (UnauthorizedAccessException) { }
                            }
                        }, 50, GetType(), _services.GetService <IIdleTimeService>());

                        return(_result);
                    }
                }
            } catch (Exception ex) {
                _exception = ex;
            }
            return(null);
        }
コード例 #16
0
ファイル: PeekTestItem.cs プロジェクト: shana/PeekTest
        public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback)
        {
            if (relationshipName != PredefinedPeekRelationships.Definitions.Name)
            {
                return;
            }

            var temp = Path.GetTempFileName();

            using (var displayInfo = new PeekResultDisplayInfo(label: peekableItem._className, labelTooltip: "Comment", title: "Comment title", titleTooltip: "Comment"))
            {
                var result = peekableItem._peekResultFactory.Create
                             (
                    displayInfo,
                    temp,
                    new Span(0, 0),
                    0,
                    false
                             );

                resultCollection.Add(result);
                callback.ReportProgress(1);
            }
        }
コード例 #17
0
        private IPeekResult CreatePeekResult(LocationInfo location)
        {
            IPeekResult result = null;
            var         path   = location.FilePath;

            if (!string.IsNullOrWhiteSpace(path))
            {
                var fi          = new FileInfo(path);
                var displayInfo = new PeekResultDisplayInfo(BuildLabel(location), path, BuildTitle(location), path);
                // TODO: the location stuff doesn't work 100% correctly. This needs to be fixed
                string contentType = null;
                var    extension   = Path.GetExtension(path);
                if (extension != null)
                {
                    switch (extension.ToLower())
                    {
                    case ".4gl":
                        contentType = VSGeneroConstants.ContentType4GL;
                        break;

                    case ".inc":
                        contentType = VSGeneroConstants.ContentTypeINC;
                        break;

                    case ".per":
                        contentType = VSGeneroConstants.ContentTypePER;
                        break;
                    }
                }
                if (contentType != null)
                {
                    ITextDocument textDoc = null;
                    int           line    = location.Line - 1;
                    if (line < 0)
                    {
                        textDoc = this._factory.TextDocumentFactoryService.CreateAndLoadTextDocument(path, this._factory.ContentTypeRegistryService.GetContentType(contentType));
                        line    = textDoc.TextBuffer.CurrentSnapshot.GetLineNumberFromPosition(location.Index);
                    }
                    int character = location.Column - 1;  // start index
                    if (character < 0)
                    {
                        character = 0;
                    }
                    //EditorExtensions.EditorExtensions.GetLineAndColumnOfFile(path, location.Position, out line, out character);
                    int  endLine      = line + 10; // end line
                    int  endIndex     = 0;         // end index
                    int  positionLine = 0;         // id line
                    int  positionChar = 0;         // id index
                    bool isReadOnly   = fi.IsReadOnly;

                    // TODO: determine the stuff above.

                    result           = this._factory.PeekResultFactory.Create(displayInfo, path, line, character, endLine, endIndex, positionLine, positionChar, isReadOnly);
                    result.Disposed += (x, y) =>
                    {
                        if (textDoc != null)
                        {
                            textDoc.Dispose();
                        }
                    };
                }
            }
            else if (!string.IsNullOrWhiteSpace(location.DefinitionURL))
            {
#if DEV14_OR_LATER
                return(new UrlPeekResult(location.GetUrlString(_languageVersion)));
#endif
            }
            return(result);
        }