Ejemplo n.º 1
0
 public FSharpCodeCompletionContext([NotNull] CodeCompletionContext context,
                                    FSharpOption <CompletionContext> fsCompletionContext, TextLookupRanges ranges, DocumentCoords coords,
                                    PartialLongName partialLongName, ITreeNode tokenBeforeCaret = null, ITreeNode tokenAtCaret = null,
                                    string lineText = null) : base(context)
 {
     Ranges              = ranges;
     Coords              = coords;
     PartialLongName     = partialLongName;
     TokenBeforeCaret    = tokenBeforeCaret;
     TokenAtCaret        = tokenAtCaret;
     LineText            = lineText;
     FsCompletionContext = fsCompletionContext;
 }
        /// <summary>
        /// Gets the location associated with a declared element.
        /// </summary>
        /// <param name="declaredElement">The declared element.</param>
        /// <returns>The resulting code location.</returns>
        protected static CodeLocation GetDeclaredElementSourceLocation(IDeclaredElement declaredElement)
        {
            IList <IDeclaration> decl = declaredElement.GetDeclarations();

            if (decl.Count == 0)
            {
                return(CodeLocation.Unknown);
            }

            ReSharperDocumentRange range = decl[0].GetDocumentRange();

#if RESHARPER_31 || RESHARPER_40 || RESHARPER_41
            bool isValid = range.IsValid;
#else
            bool isValid = range.IsValid();
#endif
            if (isValid)
            {
                return(CodeLocation.Unknown);
            }

#if RESHARPER_60_OR_NEWER
            var projectFile = decl[0].GetSourceFile().ToProjectFile();
#else
            var projectFile = decl[0].GetProjectFile();
#endif
            if (projectFile == null)
            {
                return(CodeLocation.Unknown);
            }

            string         filename = projectFile.Location.FullPath;
            DocumentCoords start    = range.Document.GetCoordsByOffset(range.TextRange.StartOffset);

#if !RESHARPER_50_OR_NEWER
            return(new CodeLocation(filename, start.Line, start.Column));
#else
            return(new CodeLocation(filename, (int)start.Line.Plus1(), (int)start.Column.Plus1()));
#endif
        }
Ejemplo n.º 3
0
 public static bool Contains(this Range.range range, DocumentCoords coords) =>
 range.StartLine - 1 >= (int)coords.Line && range.EndLine - 1 <= (int)coords.Line &&
 range.StartColumn >= (int)coords.Column && range.EndColumn <= (int)coords.Column;
Ejemplo n.º 4
0
 public static Range.pos GetPos(this DocumentCoords coords, int columnShift = 0)
 {
     // FCS lines are 1-based
     return(Range.mkPos((int)coords.Line + 1, (int)coords.Column + columnShift));
 }
Ejemplo n.º 5
0
        private bool HandleQuoteTyped(ITypingContext typingContext)
        {
            ITextControl textControl = typingContext.TextControl;

            if (typingContext.EnsureWritable() != EnsureWritableResult.SUCCESS)
            {
                return(false);
            }

            using (CommandProcessor.UsingCommand("Smart quote"))
            {
                TextControlUtil.DeleteSelection(textControl);
                textControl.FillVirtualSpaceUntilCaret();

                CachingLexer  lexer   = GetCachingLexer(textControl);
                IBuffer       buffer  = lexer.Buffer;
                int           charPos = TextControlToLexer(textControl, textControl.Caret.Offset());
                TokenNodeType correspondingTokenType = PsiTokenType.STRING_LITERAL;

                if (charPos < 0 || !lexer.FindTokenAt(charPos))
                {
                    return(false);
                }

                TokenNodeType tokenType = lexer.TokenType;


                // check if we should skip the typed char
                if (charPos < buffer.Length && buffer[charPos] == typingContext.Char && tokenType == correspondingTokenType &&
                    lexer.TokenStart != charPos && buffer[lexer.TokenStart] != '@')
                {
                    int position = charPos;
                    if (position >= 0)
                    {
                        textControl.Caret.MoveTo(position + 1, CaretVisualPlacement.DontScrollIfVisible);
                    }
                    return(true);
                }

                // check that next token is a good one
                if (tokenType != null && !IsStopperTokenForStringLiteral(tokenType))
                {
                    return(false);
                }


                // find next not whitespace token
                while (lexer.TokenType == PsiTokenType.WHITE_SPACE)
                {
                    lexer.Advance();
                }

                bool doInsertPairQuote = (lexer.TokenType == correspondingTokenType) &&
                                         ((lexer.TokenEnd > lexer.TokenStart + 1) && (lexer.Buffer[lexer.TokenStart] == typingContext.Char) && (lexer.Buffer[lexer.TokenEnd - 1] == typingContext.Char));

                // do inserting of the requested char and updating of the lexer
                typingContext.CallNext();
                lexer = GetCachingLexer(textControl);
                //        charPos = TextControlToLexer(textControl, textControl.CaretModel.Offset - 1);

                if (!doInsertPairQuote)
                {
                    // check if the typed char is the beginning of the corresponding token
                    if (!lexer.FindTokenAt(charPos))
                    {
                        return(true);
                    }

                    bool isStringWithAt = lexer.TokenType == PsiTokenType.STRING_LITERAL && lexer.TokenStart == charPos - 1 &&
                                          lexer.Buffer[lexer.TokenStart] == '@';
                    if ((lexer.TokenStart != charPos) && !isStringWithAt)
                    {
                        return(true);
                    }

                    // check if there is unclosed token of the corresponding type up to the end of the source line
                    int newPos = charPos;
                    if (newPos < 0)
                    {
                        return(true);
                    }

                    DocumentCoords documentCoords = textControl.Document.GetCoordsByOffset(newPos);
                    int            offset         = textControl.Document.GetLineEndOffsetNoLineBreak(documentCoords.Line) - 1;

                    int lexerOffset = TextControlToLexer(textControl, offset);
                    if (lexerOffset >= 0)
                    {
                        lexer.FindTokenAt(lexerOffset);
                    }
                    if (lexerOffset < 0 || lexer.TokenType == null)
                    {
                        charPos = TextControlToLexer(textControl, textControl.Caret.Offset() - 1);
                        if (charPos >= 0)
                        {
                            lexer.FindTokenAt(charPos);
                        }
                        else
                        {
                            return(true);
                        }
                    }

                    doInsertPairQuote = (lexer.TokenType == correspondingTokenType) &&
                                        ((lexer.TokenEnd == lexer.TokenStart + 1) || (lexer.Buffer[lexer.TokenEnd - 1] != typingContext.Char) ||
                                         (isStringWithAt && (lexer.TokenStart == charPos - 1) && (lexer.TokenEnd != charPos + 1)));
                }

                // insert paired quote
                if (doInsertPairQuote)
                {
                    charPos++;
                    int documentPos = charPos;
                    if (documentPos >= 0)
                    {
                        textControl.Document.InsertText(documentPos, typingContext.Char == '\'' ? "'" : "\"");
                        textControl.Caret.MoveTo(documentPos, CaretVisualPlacement.DontScrollIfVisible);
                    }
                }
            }

            return(true);
        }
        public CppLocation(ITreeNode treeNode)
        {
            try
            {
                this.SourceFile = treeNode.GetSourceFile().DisplayName;
                this.Id         = NextId++;

                DocumentRange documentRange = treeNode.GetNavigationRange();

                DocumentCoords start = documentRange.StartOffset.ToDocumentCoords();
                DocumentCoords end   = documentRange.EndOffset.ToDocumentCoords();

                string startLineStr = start.Line.ToString();

                startLineStr = startLineStr.Replace(",", "");

                int startLine = 0;

                if (Int32.TryParse(startLineStr, out startLine))
                {
                    StartLine = startLine + 1;
                }
                else
                {
                    LogManager.Self.Log($"CoordParse Failed: {startLineStr}");
                }

                string startColStr = start.Column.ToString();

                startColStr = startColStr.Replace(",", "");

                int startCol = 0;

                if (Int32.TryParse(startColStr, out startCol))
                {
                    StartColumn = startCol + 1;
                }
                else
                {
                    LogManager.Self.Log($"CoordParse Failed: {startColStr}");
                }

                string endLineStr = end.Line.ToString();

                endLineStr = endLineStr.Replace(",", "");

                int endLine = 0;

                if (Int32.TryParse(endLineStr, out endLine))
                {
                    EndLine = endLine + 1;
                }
                else
                {
                    LogManager.Self.Log($"CoordParse Failed: {endLineStr}");
                }

                string endColStr = end.Column.ToString();

                endColStr = endColStr.Replace(",", "");

                int endCol = 0;

                if (Int32.TryParse(endColStr, out endCol))
                {
                    EndColumn = endCol + 1;
                }
                else
                {
                    LogManager.Self.Log($"CoordParse Failed: {endColStr}");
                }
            }
            catch (Exception ex)
            {
                LogManager.Self.Log($"Location parse error");
            }
        }