示例#1
0
        public static DocumentRange CreateDocumentRange(DocumentOffset startOffset, DocumentOffset endOffset)
        {
#if OLD_MSBUILD
            return(new DocumentRange(ref startOffset, ref endOffset));
#else
            return(new DocumentRange(startOffset, endOffset));
#endif
        }
示例#2
0
        public static bool RangeContains(DocumentRange range, DocumentOffset offset)
        {
#if OLD_MSBUILD
            return(range.Contains(ref offset));
#else
            return(range.Contains(offset));
#endif
        }
示例#3
0
        public new IParameterInfoContext CreateContext(
            ISolution solution,
            DocumentOffset caretOffset,
            DocumentOffset expectedLParenthOffset,
            char invocationChar,
            IContextBoundSettingsStore settingsStore)
        {
            IParameterInfoContext context = base.CreateContext(solution, caretOffset, expectedLParenthOffset, invocationChar, settingsStore);

            return(Enhance(context, solution, settingsStore));
        }
        public IParameterInfoContext CreateContext(ISolution solution, DocumentOffset caretOffset,
                                                   DocumentOffset expectedLParenthOffset, char invocationChar, IContextBoundSettingsStore settingsStore)
        {
            var fsFile       = solution.GetPsiServices().GetPsiFile <FSharpLanguage>(caretOffset) as IFSharpFile;
            var parseResults = fsFile?.ParseResults?.Value;

            if (parseResults == null)
            {
                return(null);
            }

            var document = caretOffset.Document;
            var coords   = document.GetCoordsByOffset(caretOffset.Offset);
            var paramInfoLocationsOption = parseResults.FindNoteworthyParamInfoLocations(coords.GetPos());

            if (paramInfoLocationsOption == null)
            {
                return(null);
            }

            var checkResults = fsFile.GetParseAndCheckResults(true, OpName)?.Value.CheckResults;

            if (checkResults == null)
            {
                return(null);
            }

            var paramInfoLocations = paramInfoLocationsOption.Value;
            var names           = paramInfoLocations.LongId;
            var lidEnd          = paramInfoLocations.LongIdEndLocation;
            var getMethodsAsync =
                checkResults.GetMethods(lidEnd.Line, lidEnd.Column, string.Empty, OptionModule.OfObj(names), FSharpOption <string> .None);

            // do not show when no overloads are found or got an operator info
            // github.com/Microsoft/visualfsharp/blob/Visual-Studio-2017/vsintegration/src/FSharp.LanguageService/Intellisense.fs#L274
            var overloads = FSharpAsync.RunSynchronously(getMethodsAsync, FSharpOption <int> .Some(2000), null);

            if (overloads.Methods.IsEmpty() || overloads.MethodName.EndsWith("> )"))
            {
                return(null);
            }

            var currentParamNumber = GetParameterNumber(paramInfoLocations, caretOffset);
            var rangeStartOffset   = document.GetOffset(paramInfoLocations.OpenParenLocation);
            var textRange          = new TextRange(rangeStartOffset, document.GetLineEndOffsetNoLineBreak(coords.Line));

            var rangeStartText = document.GetText(new TextRange(rangeStartOffset, rangeStartOffset + 1));
            var namedArgs      = paramInfoLocations.NamedParamNames.TakeWhile(n => n != null).Select(n => n.Value).AsArray();
            var candidates     = CreateCandidates(rangeStartText, overloads, paramInfoLocations.TupleEndLocations.Length);

            return(new FSharpParameterInfoContext(currentParamNumber, candidates, textRange, namedArgs));
        }
        private static int GetParameterNumber(FSharpNoteworthyParamInfoLocations paramInfoLocations,
                                              DocumentOffset documentCaretOffset)
        {
            var tupleEndLocations = paramInfoLocations.TupleEndLocations;
            var offset            = documentCaretOffset.Offset;
            var document          = documentCaretOffset.Document;

            for (var i = 0; i < tupleEndLocations.Length; i++)
            {
                if (document.GetOffset(tupleEndLocations[i]) > offset)
                {
                    return(i);
                }
            }
            return(0);
        }
        public new IParameterInfoContext?CreateContext(
            ISolution solution,
            DocumentOffset caretOffset,
            DocumentOffset expectedLParenthOffset,
            char invocationChar,
            IContextBoundSettingsStore settingsStore)
        {
            IParameterInfoContext?context = base.CreateContext(solution, caretOffset, expectedLParenthOffset, invocationChar, settingsStore);

            if (context is null || !settingsStore.GetValue((ParameterInfoSettings s) => s.Enabled))
            {
                return(context);
            }

            return(new EnhancedTypeArgumentContext(
                       context,
                       settingsStore,
                       solution.GetComponent <HighlighterIdProviderFactory>(),
                       solution.GetComponent <ColorizerPresenter>()));
        }
        public new IParameterInfoContext CreateContext(
            ISolution solution,
            DocumentOffset caretOffset,
            DocumentOffset expectedLParenthOffset,
            char invocationChar,
            IContextBoundSettingsStore settingsStore)
        {
            IParameterInfoContext context = base.CreateContext(solution, caretOffset, expectedLParenthOffset, invocationChar, settingsStore);

            if (!context.CanEnhance(settingsStore))
            {
                return(context);
            }

            return(new EnhancedParameterInfoContext(
                       context,
                       settingsStore,
                       solution.GetComponent <HighlighterIdProviderFactory>(),
                       solution.GetComponent <ColorizerPresenter>()));
        }
示例#8
0
        public bool IsAvailable(IDataContext dataContext)
        {
            ISolution solution = dataContext.GetData(JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION);

            if (solution == null)
            {
                return(false);
            }
#if SDK70
            IDocument document = dataContext.GetData(JetBrains.DocumentModel.DataConstants.DOCUMENT);
#else
            IDocument document = dataContext.GetData(JetBrains.IDE.DataConstants.DOCUMENT);
#endif

            if (document == null)
            {
                return(false);
            }
#if SDK70
            DocumentOffset documentOffset = dataContext.GetData(JetBrains.DocumentModel.DataConstants.DOCUMENT_OFFSET);
#else
            DocumentOffset documentOffset = dataContext.GetData(JetBrains.IDE.DataConstants.DOCUMENT_OFFSET);
#endif
            if (documentOffset == null)
            {
                return(false);
            }
            IPsiSourceFile psiSourceFile = document.GetPsiSourceFile(solution);
            if (psiSourceFile != null)
            {
                // todo make this resolvable also via the AllTypes... line
                var invokedNode = dataContext.GetSelectedTreeNode <IExpression>();

                return(solution.GetComponent <SolutionAnalyzer>()
                       .Analyze()
                       .Any(r => r.Registration.RegistrationElement.Children().Contains(invokedNode)));
            }

            return(false);
        }
 protected CognitiveComplexityHintBase(ITreeNode node, DocumentOffset offset, int value)
 {
     _node       = node;
     _offset     = offset;
     Value       = value;
     Description = node switch
     {
         IWhileStatement _ => "While-Statement (increases nesting)",
         ISwitchStatement _ => "Switch-Statement (increases nesting)",
         IDoStatement _ => "Do-While-Statement (increases nesting)",
         IIfStatement _ => "If-Statement (increases nesting)",
         IForStatement _ => "For-Statement (increases nesting)",
         IForeachStatement _ => "Foreach-Statement (increases nesting)",
         ICatchClause _ => "Catch-Clause (increases nesting)",
         IGotoStatement _ => "Goto-Statement",
         IBreakStatement _ => "Break-Statement",
         IConditionalOrExpression _ => "First/alternating conditional Expression",
         IConditionalAndExpression _ => "First/alternating conditional Expression",
         ICSharpStatement _ => "If-Statement (increases nesting)",
         ICSharpExpression _ => "Recursive Call",
                         _ => throw new NotSupportedException(node.GetType().FullName)
     };
 }
示例#10
0
        public string GetStepTextBeforeCaret(DocumentOffset caretLocation)
        {
            var sb = new StringBuilder();

            for (var te = GetFirstTextToken(); te != null; te = te.NextSibling)
            {
                if (te.GetDocumentStartOffset() > caretLocation)
                {
                    break;
                }
                var truncateTextSize = 0;
                if (te.GetDocumentEndOffset() > caretLocation)
                {
                    truncateTextSize = te.GetDocumentEndOffset().Offset - caretLocation.Offset;
                }
                switch (te)
                {
                case GherkinStepParameter p:
                    sb.Append(p.GetText());
                    break;

                case GherkinToken token:
                    if (token.NodeType != GherkinTokenTypes.STEP_KEYWORD)
                    {
                        sb.Append(token.GetText());
                    }
                    break;
                }
                if (truncateTextSize >= sb.Length)
                {
                    return(string.Empty);
                }
                sb.Length -= truncateTextSize;
            }
            return(sb.ToString().Trim());
        }
示例#11
0
        private static bool IsSelectedElementAssociatedWithRegistration(IDataContext dataContext)
        {
            ISolution solution = dataContext.GetData(JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION);

            if (solution == null)
            {
                return(false);
            }
            IDocument document = dataContext.GetData(JetBrains.DocumentModel.DataConstants.DOCUMENT);

            if (document == null)
            {
                return(false);
            }

            DocumentOffset documentOffset = dataContext.GetData(JetBrains.DocumentModel.DataConstants.DOCUMENT_OFFSET);

            if (documentOffset == null)
            {
                return(false);
            }

            IPsiSourceFile psiSourceFile = document.GetPsiSourceFile(solution);

            if (psiSourceFile != null)
            {
                // todo make this resolvable also via the AllTypes... line
                var invokedNode = dataContext.GetSelectedTreeNode <IExpression>();

                return(solution.GetComponent <IPatternManager>()
                       .GetRegistrationsForFile(psiSourceFile)
                       .Any(r => r.Registration.RegistrationElement.Children().Contains(invokedNode)));
            }

            return(false);
        }
示例#12
0
 public CognitiveComplexityErrorHint(ITreeNode node, DocumentOffset offset, int value)
     : base(node, offset, value)
 {
 }
 public bool ShouldPopup(DocumentOffset caretOffset, char c, ISolution solution,
                         IContextBoundSettingsStore settingsStore)
 {
     return(ourPopupChars.Contains(c));
 }
        public ReplacingAllowedPrefixCharsScopePoint(ITemplateScopePoint innerScopePoint, DocumentOffset caretOffset, char[] allowedPrefixChars)
            : base(innerScopePoint)
        {
            this.allowedPrefixChars = allowedPrefixChars;

            Prefix = CalcPrefix(caretOffset);
        }
 public override string CalcPrefix(DocumentOffset caretOffset)
 {
     return(LiveTemplatesManager.GetPrefix(caretOffset, allowedPrefixChars));
 }
示例#16
0
 public abstract string CalcPrefix(DocumentOffset caretOffset);
示例#17
0
 protected CognitiveComplexityHintBase(ITreeNode node, DocumentOffset offset, int value)
 {
     _node   = node;
     _offset = offset;
     Value   = value;
 }