Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit 6d51ad8

Browse files
dsymeDon Syme
authored andcommitted
Correct IDE diagnostics and lifetimes for editing with #r package references (dotnet#10160)
Co-authored-by: Don Syme <[email protected]>
1 parent c70ec41 commit 6d51ad8

File tree

10 files changed

+69
-46
lines changed

10 files changed

+69
-46
lines changed

CodeFix/AddOpenCodeFixProvider.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ type internal FSharpAddOpenCodeFixProvider
105105

106106
let! symbol =
107107
asyncMaybe {
108-
let! lexerSymbol = Tokenizer.getSymbolAtPosition(document.Id, sourceText, context.Span.End, document.FilePath, defines, SymbolLookupKind.Greedy, false)
108+
let! lexerSymbol = Tokenizer.getSymbolAtPosition(document.Id, sourceText, context.Span.End, document.FilePath, defines, SymbolLookupKind.Greedy, false, false)
109109
return! checkResults.GetSymbolUseAtLocation(Line.fromZ linePos.Line, lexerSymbol.Ident.idRange.EndColumn, line.ToString(), lexerSymbol.FullIsland, userOpName=userOpName)
110110
} |> liftAsync
111111

CodeFix/ImplementInterfaceCodeFixProvider.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ type internal FSharpImplementInterfaceCodeFixProvider
169169
| _ ->
170170
Some context.Span.End
171171
let! interfaceState = queryInterfaceState appendBracketAt interfacePos tokens parsedInput
172-
let! symbol = Tokenizer.getSymbolAtPosition(context.Document.Id, sourceText, fixupPosition, context.Document.FilePath, defines, SymbolLookupKind.Greedy, false)
172+
let! symbol = Tokenizer.getSymbolAtPosition(context.Document.Id, sourceText, fixupPosition, context.Document.FilePath, defines, SymbolLookupKind.Greedy, false, false)
173173
let fcsTextLineNumber = textLine.LineNumber + 1
174174
let lineContents = textLine.ToString()
175175
let! options = context.Document.GetOptionsAsync(cancellationToken)

CodeFix/RenameUnusedValue.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type internal FSharpRenameUnusedValueCodeFixProvider
6161
let! _, _, checkResults = checker.ParseAndCheckDocument(document, projectOptions, sourceText = sourceText, userOpName=userOpName)
6262
let m = RoslynHelpers.TextSpanToFSharpRange(document.FilePath, context.Span, sourceText)
6363
let defines = CompilerEnvironment.GetCompilationDefinesForEditing parsingOptions
64-
let! lexerSymbol = Tokenizer.getSymbolAtPosition (document.Id, sourceText, context.Span.Start, document.FilePath, defines, SymbolLookupKind.Greedy, false)
64+
let! lexerSymbol = Tokenizer.getSymbolAtPosition (document.Id, sourceText, context.Span.Start, document.FilePath, defines, SymbolLookupKind.Greedy, false, false)
6565
let lineText = (sourceText.Lines.GetLineFromPosition context.Span.Start).ToString()
6666
let! symbolUse = checkResults.GetSymbolUseAtLocation(m.StartLine, m.EndColumn, lineText, lexerSymbol.FullIsland, userOpName=userOpName)
6767
let symbolName = symbolUse.Symbol.DisplayName

DocumentHighlights/DocumentHighlightsService.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type internal FSharpDocumentHighlightsService [<ImportingConstructor>] (checkerP
5858
let textLine = sourceText.Lines.GetLineFromPosition(position)
5959
let textLinePos = sourceText.Lines.GetLinePosition(position)
6060
let fcsTextLineNumber = Line.fromZ textLinePos.Line
61-
let! symbol = Tokenizer.getSymbolAtPosition(documentKey, sourceText, position, filePath, defines, SymbolLookupKind.Greedy, false)
61+
let! symbol = Tokenizer.getSymbolAtPosition(documentKey, sourceText, position, filePath, defines, SymbolLookupKind.Greedy, false, false)
6262
let! _, _, checkFileResults = checker.ParseAndCheckDocument(filePath, textVersionHash, sourceText, options, languageServicePerformanceOptions, userOpName = userOpName)
6363
let! symbolUse = checkFileResults.GetSymbolUseAtLocation(fcsTextLineNumber, symbol.Ident.idRange.EndColumn, textLine.ToString(), symbol.FullIsland, userOpName=userOpName)
6464
let! symbolUses = checkFileResults.GetUsesOfSymbolInFile(symbolUse.Symbol) |> liftAsync

InlineRename/InlineRenameService.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ type internal InlineRenameService
155155
let textLine = sourceText.Lines.GetLineFromPosition(position)
156156
let textLinePos = sourceText.Lines.GetLinePosition(position)
157157
let fcsTextLineNumber = Line.fromZ textLinePos.Line
158-
let! symbol = Tokenizer.getSymbolAtPosition(document.Id, sourceText, position, document.FilePath, defines, SymbolLookupKind.Greedy, false)
158+
let! symbol = Tokenizer.getSymbolAtPosition(document.Id, sourceText, position, document.FilePath, defines, SymbolLookupKind.Greedy, false, false)
159159
let! _, _, checkFileResults = checker.ParseAndCheckDocument(document, options, userOpName = userOpName)
160160
let! symbolUse = checkFileResults.GetSymbolUseAtLocation(fcsTextLineNumber, symbol.Ident.idRange.EndColumn, textLine.Text.ToString(), symbol.FullIsland, userOpName=userOpName)
161161
let! declLoc = symbolUse.GetDeclarationLocation(document)

LanguageService/SymbolHelpers.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module internal SymbolHelpers =
2727
let fcsTextLineNumber = Line.fromZ textLinePos.Line
2828
let! parsingOptions, projectOptions = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document, cancellationToken, userOpName)
2929
let defines = CompilerEnvironment.GetCompilationDefinesForEditing parsingOptions
30-
let! symbol = Tokenizer.getSymbolAtPosition(document.Id, sourceText, position, document.FilePath, defines, SymbolLookupKind.Greedy, false)
30+
let! symbol = Tokenizer.getSymbolAtPosition(document.Id, sourceText, position, document.FilePath, defines, SymbolLookupKind.Greedy, false, false)
3131
let settings = document.FSharpOptions
3232
let! _, _, checkFileResults = checker.ParseAndCheckDocument(document.FilePath, textVersionHash, sourceText, projectOptions, settings.LanguageServicePerformance, userOpName = userOpName)
3333
let! symbolUse = checkFileResults.GetSymbolUseAtLocation(fcsTextLineNumber, symbol.Ident.idRange.EndColumn, textLine.ToString(), symbol.FullIsland, userOpName=userOpName)
@@ -120,7 +120,7 @@ module internal SymbolHelpers =
120120
do! Option.guard (originalText.Length > 0)
121121
let! parsingOptions, projectOptions = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document, cancellationToken, userOpName)
122122
let defines = CompilerEnvironment.GetCompilationDefinesForEditing parsingOptions
123-
let! symbol = Tokenizer.getSymbolAtPosition(document.Id, sourceText, symbolSpan.Start, document.FilePath, defines, SymbolLookupKind.Greedy, false)
123+
let! symbol = Tokenizer.getSymbolAtPosition(document.Id, sourceText, symbolSpan.Start, document.FilePath, defines, SymbolLookupKind.Greedy, false, false)
124124
let! _, _, checkFileResults = checker.ParseAndCheckDocument(document, projectOptions, userOpName = userOpName)
125125
let textLine = sourceText.Lines.GetLineFromPosition(symbolSpan.Start)
126126
let textLinePos = sourceText.Lines.GetLinePosition(symbolSpan.Start)

LanguageService/Tokenizer.fs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ type internal LexerSymbolKind =
3333
| GenericTypeParameter = 3
3434
| StaticallyResolvedTypeParameter = 4
3535
| ActivePattern = 5
36-
| Other = 6
36+
| String = 6
37+
| Other = 7
3738

3839
type internal LexerSymbol =
3940
{ Kind: LexerSymbolKind
@@ -147,11 +148,14 @@ module internal Tokenizer =
147148
| FSharpGlyph.Variable -> Glyph.Local
148149
| FSharpGlyph.Error -> Glyph.Error
149150

150-
let GetImageIdForSymbol(symbol:FSharpSymbol, kind:LexerSymbolKind) =
151+
let GetImageIdForSymbol(symbolOpt:FSharpSymbol option, kind:LexerSymbolKind) =
151152
let imageId =
152153
match kind with
153154
| LexerSymbolKind.Operator -> KnownImageIds.Operator
154155
| _ ->
156+
match symbolOpt with
157+
| None -> KnownImageIds.Package
158+
| Some symbol ->
155159
match symbol with
156160
| :? FSharpUnionCase as x ->
157161
match Some x.Accessibility with
@@ -345,6 +349,7 @@ module internal Tokenizer =
345349
member token.IsIdentifier = (token.CharClass = FSharpTokenCharKind.Identifier)
346350
member token.IsOperator = (token.ColorClass = FSharpTokenColorKind.Operator)
347351
member token.IsPunctuation = (token.ColorClass = FSharpTokenColorKind.Punctuation)
352+
member token.IsString = (token.ColorClass = FSharpTokenColorKind.String)
348353

349354
/// This is the information we save for each token in a line for each active document.
350355
/// It is a memory-critical data structure - do not make larger. This used to be ~100 bytes class, is now 8-byte struct
@@ -375,6 +380,7 @@ module internal Tokenizer =
375380
if token.IsOperator then LexerSymbolKind.Operator
376381
elif token.IsIdentifier then LexerSymbolKind.Ident
377382
elif token.IsPunctuation then LexerSymbolKind.Punctuation
383+
elif token.IsString then LexerSymbolKind.String
378384
else LexerSymbolKind.Other
379385
Debug.Assert(uint32 token.Tag < 0xFFFFu)
380386
Debug.Assert(uint32 kind < 0xFFu)
@@ -612,7 +618,8 @@ module internal Tokenizer =
612618
linePos: LinePosition,
613619
lineStr: string,
614620
lookupKind: SymbolLookupKind,
615-
wholeActivePatterns: bool
621+
wholeActivePatterns: bool,
622+
allowStringToken: bool
616623
)
617624
: LexerSymbol option =
618625

@@ -704,6 +711,7 @@ module internal Tokenizer =
704711
| LexerSymbolKind.StaticallyResolvedTypeParameter -> true
705712
| _ -> false)
706713
|> Option.orElseWith (fun _ -> tokensUnderCursor |> List.tryFind (fun token -> token.Kind = LexerSymbolKind.Operator))
714+
|> Option.orElseWith (fun _ -> if allowStringToken then tokensUnderCursor |> List.tryFind (fun token -> token.Kind = LexerSymbolKind.String) else None)
707715
|> Option.map (fun token ->
708716
let partialName = QuickParse.GetPartialLongNameEx(lineStr, token.RightColumn)
709717
let identStr = lineStr.Substring(token.LeftColumn, token.MatchedLength)
@@ -767,13 +775,14 @@ module internal Tokenizer =
767775
fileName: string,
768776
defines: string list,
769777
lookupKind: SymbolLookupKind,
770-
wholeActivePatterns: bool
778+
wholeActivePatterns: bool,
779+
allowStringToken: bool
771780
)
772781
: LexerSymbol option =
773782

774783
try
775784
let lineData, textLinePos, lineContents = getCachedSourceLineData(documentKey, sourceText, position, fileName, defines)
776-
getSymbolFromSavedTokens(fileName, lineData.SavedTokens, textLinePos, lineContents, lookupKind, wholeActivePatterns)
785+
getSymbolFromSavedTokens(fileName, lineData.SavedTokens, textLinePos, lineContents, lookupKind, wholeActivePatterns, allowStringToken)
777786
with
778787
| :? System.OperationCanceledException -> reraise()
779788
| ex ->

Navigation/FindUsagesService.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type internal FSharpFindUsagesService
5757
let lineNumber = sourceText.Lines.GetLinePosition(position).Line + 1
5858
let defines = CompilerEnvironment.GetCompilationDefinesForEditing parsingOptions
5959

60-
let! symbol = Tokenizer.getSymbolAtPosition(document.Id, sourceText, position, document.FilePath, defines, SymbolLookupKind.Greedy, false)
60+
let! symbol = Tokenizer.getSymbolAtPosition(document.Id, sourceText, position, document.FilePath, defines, SymbolLookupKind.Greedy, false, false)
6161
let! symbolUse = checkFileResults.GetSymbolUseAtLocation(lineNumber, symbol.Ident.idRange.EndColumn, textLine, symbol.FullIsland, userOpName=userOpName)
6262
let! declaration = checkFileResults.GetDeclarationLocation (lineNumber, symbol.Ident.idRange.EndColumn, textLine, symbol.FullIsland, false, userOpName=userOpName) |> liftAsync
6363
let tags = FSharpGlyphTags.GetTags(Tokenizer.GetGlyphForSymbol (symbolUse.Symbol, symbol.Kind))

Navigation/GoToDefinition.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ type internal GoToDefinition(checker: FSharpChecker, projectInfoManager: FSharpP
152152
let defines = CompilerEnvironment.GetCompilationDefinesForEditing parsingOptions
153153
let! originTextSpan = RoslynHelpers.TryFSharpRangeToTextSpan (sourceText, originRange)
154154
let position = originTextSpan.Start
155-
let! lexerSymbol = Tokenizer.getSymbolAtPosition (originDocument.Id, sourceText, position, originDocument.FilePath, defines, SymbolLookupKind.Greedy, false)
155+
let! lexerSymbol = Tokenizer.getSymbolAtPosition (originDocument.Id, sourceText, position, originDocument.FilePath, defines, SymbolLookupKind.Greedy, false, false)
156156

157157
let textLinePos = sourceText.Lines.GetLinePosition position
158158
let fcsTextLineNumber = Line.fromZ textLinePos.Line
@@ -212,7 +212,7 @@ type internal GoToDefinition(checker: FSharpChecker, projectInfoManager: FSharpP
212212

213213
let! _, _, checkFileResults = checker.ParseAndCheckDocument (originDocument, projectOptions, sourceText=sourceText, userOpName=userOpName)
214214

215-
let! lexerSymbol = Tokenizer.getSymbolAtPosition (originDocument.Id, sourceText, position,originDocument.FilePath, defines, SymbolLookupKind.Greedy, false)
215+
let! lexerSymbol = Tokenizer.getSymbolAtPosition (originDocument.Id, sourceText, position,originDocument.FilePath, defines, SymbolLookupKind.Greedy, false, false)
216216
let idRange = lexerSymbol.Ident.idRange
217217

218218
let! declarations = checkFileResults.GetDeclarationLocation (fcsTextLineNumber, lexerSymbol.Ident.idRange.EndColumn, textLine.ToString(), lexerSymbol.FullIsland, preferSignature, userOpName=userOpName) |> liftAsync

0 commit comments

Comments
 (0)