Beispiel #1
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);
                }
            }
        }
 /// <summary>
 /// Populates the collection of <see cref="IPeekResult"/>s for the given relationship.
 /// </summary>
 /// <param name="relationshipName">The case insenitive name of the relationship to be queried for results.</param>
 /// <param name="resultCollection">Represents a collection of <see cref="IPeekResult"/>s to be populated.</param>
 /// <param name="cancellationToken">The cancellation token used by the caller to cancel the operation.</param>
 /// <param name="callback">The <see cref="IFindPeekResultsCallback"/> instance used to report progress and failures.</param>
 public void FindResults(string relationshipName, IPeekResultCollection collection, CancellationToken cancellationToken, IFindPeekResultsCallback callback)
 {
     if (relationshipName.Equals(CommentPeek.RelationshipName, StringComparison.OrdinalIgnoreCase))
     {
         // todo: Add IPeekResults to IPeekResultCollection
     }
 }
        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);
            }
        }
        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);
                }
            }
        }
Beispiel #5
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._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);
            }
        }
Beispiel #6
0
 public void FindResults(string relationshipName, IPeekResultCollection resultCollection,
                         CancellationToken cancellationToken, IFindPeekResultsCallback callback)
 {
     if (relationshipName == _relName)
     {
         resultCollection.Add(new RotPeekResult(_expandedTactic));
     }
 }
Beispiel #7
0
            public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback)
            {
                if (relationshipName != _peekableItem._relationship.Name)
                {
                    return;
                }

                resultCollection.Add(PeekHelpers.CreateDocumentPeekResult(_peekableItem._span.Path, _peekableItem._span.Span, _peekableItem._span.Span, _peekableItem.PeekResultFactory));
            }
            public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback)
            {
                if (relationshipName != _peekableItem._relationship.Name)
                {
                    return;
                }

                resultCollection.Add(PeekHelpers.CreateDocumentPeekResult(_peekableItem._span.Path, _peekableItem._span.Span, _peekableItem._span.Span, _peekableItem.PeekResultFactory));
            }
        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);
            }
        }
Beispiel #10
0
        public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback)
        {
            if (resultCollection == null)
            {
                throw new ArgumentNullException(nameof(resultCollection));
            }

            if (!string.Equals(relationshipName, PredefinedPeekRelationships.Definitions.Name, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            resultCollection.Add(CreateResult());
        }
Beispiel #11
0
 public void FindResults(string relationshipName, IPeekResultCollection resultCollection, System.Threading.CancellationToken cancellationToken, IFindPeekResultsCallback callback)
 {
     if (relationshipName == PredefinedPeekRelationships.Definitions.Name)
     {
         foreach (var location in _locations)
         {
             IPeekResult result = CreatePeekResult(location);
             if (result != null)
             {
                 resultCollection.Add(result);
             }
         }
     }
 }
Beispiel #12
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);
            }
        }
        public void FindResults(string relationshipName,
                                IPeekResultCollection resultCollection,
                                CancellationToken cancellationToken,
                                IFindPeekResultsCallback callback) {
            if (relationshipName != PredefinedPeekRelationships.Definitions.Name) {
                return;
            }

            // If task is still running, wait a bit, but not too long.
            LookupTask.Wait(_shell.IsUnitTestEnvironment ? 50000 : 2000);
            if (_exception != null) {
                callback.ReportFailure(_exception);
            } else if (LookupTask.IsCompleted && LookupTask.Result != null) {
                resultCollection.Add(LookupTask.Result);
            }
        }
Beispiel #14
0
        public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback)
        {
            if (resultCollection == null)
            {
                throw new ArgumentNullException(nameof(resultCollection));
            }

            if (!string.Equals(relationshipName, PredefinedPeekRelationships.Definitions.Name, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            foreach (var variable in _variables.Where(v => !string.IsNullOrEmpty(v.Location.FilePath)))
            {
                resultCollection.Add(CreateResult(variable));
            }
        }
            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);
                }
            }
Beispiel #16
0
        public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback)
        {
            if (resultCollection == null)
            {
                throw new ArgumentNullException(nameof(resultCollection));
            }

            if (!string.Equals(relationshipName, PredefinedPeekRelationships.Definitions.Name, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var grouped = _variables.Where(v => !string.IsNullOrEmpty(v.Location.FilePath))
                          .OrderByDescending(v => v.Location.EndLine - v.Location.StartLine)
                          .ThenBy(v => v.Location.StartLine)
                          .GroupBy(v => v.Location.FilePath);

            var valueAndDefs = new List <IDocumentPeekResult>();
            var defOnly      = new List <IDocumentPeekResult>();

            foreach (var g in grouped)
            {
                bool anyValues = false;
                foreach (var value in g.Where(v => v.Type == VariableType.Value))
                {
                    var def = g.FirstOrDefault(v => v.Type == VariableType.Value && LocationContains(value.Location, v.Location))?.Location ??
                              new LocationInfo(value.Location.FilePath, value.Location.DocumentUri, value.Location.StartLine, value.Location.StartColumn);
                    valueAndDefs.Add(CreateResult(g.Key, def, value.Location));
                    anyValues = true;
                }
                if (!anyValues)
                {
                    foreach (var def in g.Where(v => v.Type == VariableType.Definition))
                    {
                        defOnly.Add(CreateResult(g.Key, def.Location));
                    }
                }
            }

            foreach (var v in valueAndDefs.Concat(defOnly))
            {
                resultCollection.Add(v);
            }
        }
        public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback)
        {
            try
            {
                if (relationshipName != PredefinedPeekRelationships.Definitions.Name)
                {
                    return;
                }
                var fileName = Path.GetFileName(this.peekableItem._gotoElement.File.FullPath);
                if (string.IsNullOrEmpty(fileName))
                {
                    return;
                }
                var label = this.peekableItem._gotoElement.Name;
                var title = string.Format("{0} - ({1}, {2})", fileName, this.peekableItem._gotoElement.Range.StartLine, this.peekableItem._gotoElement.Range.StartColumn + 1);

                using (var displayInfo = new PeekResultDisplayInfo2(label: label, labelTooltip: this.peekableItem._gotoElement.File.FullPath, title: title, titleTooltip: this.peekableItem._gotoElement.File.FullPath, startIndexOfTokenInLabel: 0, lengthOfTokenInLabel: label.Length))
                {
                    var result = peekableItem._peekResultFactory.Create
                                 (
                        displayInfo,
                        default(ImageMoniker),
                        this.peekableItem._gotoElement.File.FullPath,
                        this.peekableItem._gotoElement.Range.StartLine,
                        this.peekableItem._gotoElement.Range.StartColumn - 1,
                        this.peekableItem._gotoElement.Range.EndLine,
                        this.peekableItem._gotoElement.Range.EndColumn - 1,
                        this.peekableItem._gotoElement.Range.StartLine,
                        this.peekableItem._gotoElement.Range.StartColumn - 1,
                        this.peekableItem._gotoElement.Range.EndLine,
                        this.peekableItem._gotoElement.Range.EndColumn - 1,
                        false,
                        new Guid(XSharpConstants.EditorFactoryGuidString)
                                 );

                    resultCollection.Add(result);
                    callback.ReportProgress(1);
                }
            }
            catch (Exception ex)
            {
                XSettings.LogException(ex, "XSharpResultSource.FindResults failed : ");
            }
        }
            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);
                }
            }
Beispiel #19
0
        public void FindResults(string relationshipName,
                                IPeekResultCollection resultCollection,
                                CancellationToken cancellationToken,
                                IFindPeekResultsCallback callback)
        {
            if (relationshipName != PredefinedPeekRelationships.Definitions.Name)
            {
                return;
            }

            // If task is still running, wait a bit, but not too long.
            LookupTask.Wait(TestEnvironment.Current != null ? 50000 : 2000);
            if (_exception != null)
            {
                callback.ReportFailure(_exception);
            }
            else if (LookupTask.IsCompleted && LookupTask.Result != null)
            {
                resultCollection.Add(LookupTask.Result);
            }
        }
Beispiel #20
0
        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);
            }
        }
Beispiel #21
0
        private IPeekResult CreatePeekResult(IPeekResultCollection resultCollection, LocationInfo location)
        {
            IPeekResult result      = null;
            var         path        = location.FilePath;
            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();
                    }
                };
            }
            return(result);
        }
 /// <summary>
 /// Populates the collection of <see cref="IPeekResult"/>s for the given relationship.
 /// </summary>
 /// <param name="relationshipName">The case insenitive name of the relationship to be queried for results.</param>
 /// <param name="resultCollection">Represents a collection of <see cref="IPeekResult"/>s to be populated.</param>
 /// <param name="cancellationToken">The cancellation token used by the caller to cancel the operation.</param>
 /// <param name="callback">The <see cref="IFindPeekResultsCallback"/> instance used to report progress and failures.</param>
 public void FindResults(string relationshipName, IPeekResultCollection collection, CancellationToken cancellationToken, IFindPeekResultsCallback callback)
 {
     if (relationshipName.Equals($rootSafeItemName$.RelationshipName, StringComparison.OrdinalIgnoreCase))
     {
         // todo: Add IPeekResults to IPeekResultCollection
     }
 }
Beispiel #23
0
 public void FindResults(string relationshipName, IPeekResultCollection resultCollection,
                         CancellationToken cancellationToken, IFindPeekResultsCallback callback)
 {
     resultCollection.Add(new F1PeekResult(_helpUrl));
 }
Beispiel #24
0
 public void FindResults(string relationshipName, IPeekResultCollection resultCollection,
     CancellationToken cancellationToken, IFindPeekResultsCallback callback)
 {
     resultCollection.Add(new F1PeekResult(_helpUrl));
 }
Beispiel #25
0
 public void FindResults(string relationshipName, IPeekResultCollection resultCollection, 
   CancellationToken cancellationToken, IFindPeekResultsCallback callback)
 {
   if(relationshipName==_relName) resultCollection.Add(new RotPeekResult(_expandedTactic));
 }
 public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback)
 {
     resultCollection.Add(new InlineCommentPeekResult(viewModel));
 }