Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite76a7c0

Browse files
vasily-kirichenkoKevinRansom
authored andcommitted
Fix quick info for namespaces (dotnet#2298)
* CommonHelpers.getSymbolFromTokens returns full long ident island which is passed to FCS* fixed: QuickInfo is not shown for trailing ^ operatorfixed: QuickInfo is shown when cursor is beyond symbol at one column to the right* fix QuickInfoProvider test
1 parenta25bfd1 commite76a7c0

File tree

10 files changed

+74
-95
lines changed

10 files changed

+74
-95
lines changed

‎vsintegration/src/FSharp.Editor/CodeFix/ImplementInterfaceCodeFixProvider.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,12 @@ type internal FSharpImplementInterfaceCodeFixProvider
171171
|_->
172172
Some context.Span.End
173173
let!interfaceState= queryInterfaceState appendBracketAt interfacePos tokens parsedInput
174-
let!symbol= CommonHelpers.getSymbolAtPosition(context.Document.Id, sourceText, fixupPosition, context.Document.FilePath, defines, SymbolLookupKind.Fuzzy)
174+
let!symbol= CommonHelpers.getSymbolAtPosition(context.Document.Id, sourceText, fixupPosition, context.Document.FilePath, defines, SymbolLookupKind.Greedy)
175175
letfcsTextLineNumber= textLine.LineNumber+1
176176
letlineContents= textLine.ToString()
177177
let!options= context.Document.GetOptionsAsync(cancellationToken)
178178
lettabSize= options.GetOption(FormattingOptions.TabSize, FSharpCommonConstants.FSharpLanguageName)
179-
let!symbolUse= checkFileResults.GetSymbolUseAtLocation(fcsTextLineNumber, symbol.RightColumn, lineContents,[symbol.Text])
179+
let!symbolUse= checkFileResults.GetSymbolUseAtLocation(fcsTextLineNumber, symbol.Ident.idRange.EndColumn, lineContents, symbol.FullIsland)
180180
let!entity,displayContext=
181181
match symbolUse.Symbolwith
182182
|:? FSharpEntity as entity->

‎vsintegration/src/FSharp.Editor/Common/CommonHelpers.fs‎

Lines changed: 43 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ open Microsoft.CodeAnalysis.Text
1414

1515
openMicrosoft.VisualStudio.FSharp.LanguageService
1616
openMicrosoft.FSharp.Compiler
17+
openMicrosoft.FSharp.Compiler.Ast
1718
openMicrosoft.FSharp.Compiler.SourceCodeServices
1819
openMicrosoft.FSharp.Compiler.SourceCodeServices.ItemDescriptionIcons
1920

@@ -27,19 +28,18 @@ type internal LexerSymbolKind =
2728

2829
typeinternalLexerSymbol=
2930
{ Kind:LexerSymbolKind
30-
Line:int
31-
LeftColumn:int
32-
RightColumn:int
33-
Text:string
34-
FileName:string}
35-
memberx.Range:Range.range=
36-
Range.mkRange x.FileName(Range.mkPos(x.Line+1) x.LeftColumn)(Range.mkPos(x.Line+1) x.RightColumn)
31+
/// Last part of `LongIdent`
32+
Ident:Ident
33+
/// All parts of `LongIdent`
34+
FullIsland:string list}
35+
memberx.Range:Range.range= x.Ident.idRange
3736

3837
[<RequireQualifiedAccess>]
3938
typeinternalSymbolLookupKind=
40-
| Fuzzy
41-
| ByRightColumn
42-
| ByLongIdent
39+
/// Position must lay inside symbol range.
40+
| Precise
41+
/// Position may lay one column outside of symbol range to the right.
42+
| Greedy
4343

4444
moduleinternalCommonHelpers=
4545
typeprivateSourceLineData(lineStart: int,lexStateAtStartOfLine: FSharpTokenizerLexState,lexStateAtEndOfLine: FSharpTokenizerLexState,
@@ -219,15 +219,17 @@ module internal CommonHelpers =
219219
// and FullMathedLength (for "^type" which is tokenized as (INFIX_AT_HAT_OP, left=2) + (IDENT, left=3, length=4)
220220
// we'll get (IDENT, left=2, length=5).
221221
lettokens=
222+
lettokensCount= tokens.Length
222223
tokens
223-
|> List.fold(fun(acc,lastToken)(token: FSharpTokenInfo)->
224+
|> List.foldi(fun(acc,lastToken)index(token: FSharpTokenInfo)->
224225
match lastTokenwith
225226
| Some twhen token.LeftColumn<= t.RightColumn-> acc, lastToken
226227
|_->
228+
letisLastToken= index= tokensCount-1
227229
match tokenwith
228-
| GenericTypeParameterPrefix-> acc, Some(DraftToken.Create LexerSymbolKind.GenericTypeParameter token)
229-
| StaticallyResolvedTypeParameterPrefix-> acc, Some(DraftToken.Create LexerSymbolKind.StaticallyResolvedTypeParameter token)
230-
|Other->
230+
| GenericTypeParameterPrefixwhennot isLastToken-> acc, Some(DraftToken.Create LexerSymbolKind.GenericTypeParameter token)
231+
| StaticallyResolvedTypeParameterPrefixwhennot isLastToken-> acc, Some(DraftToken.Create LexerSymbolKind.StaticallyResolvedTypeParameter token)
232+
|_->
231233
letdraftToken=
232234
match lastTokenwith
233235
| Some{ Kind= LexerSymbolKind.GenericTypeParameter| LexerSymbolKind.StaticallyResolvedTypeParameteras kind}when isIdentifier token->
@@ -250,66 +252,34 @@ module internal CommonHelpers =
250252

251253
// One or two tokens that in touch with the cursor (for "let x|(g) = ()" the tokens will be "x" and "(")
252254
lettokensUnderCursor=
253-
match lookupKindwith
254-
| SymbolLookupKind.Fuzzy->
255-
tokens|> List.filter(fun x-> x.Token.LeftColumn<= linePos.Character&& x.RightColumn+1>= linePos.Character)
256-
| SymbolLookupKind.ByRightColumn->
257-
tokens|> List.filter(fun x-> x.RightColumn= linePos.Character)
258-
| SymbolLookupKind.ByLongIdent->
259-
tokens|> List.filter(fun x-> x.Token.LeftColumn<= linePos.Character)
260-
261-
//printfn "Filtered tokens: %+A" tokensUnderCursor
262-
match lookupKindwith
263-
| SymbolLookupKind.ByLongIdent->
264-
// Try to find start column of the long identifiers
265-
// Assume that tokens are ordered in an decreasing order of start columns
266-
let rectryFindStartColumn tokens=
267-
match tokenswith
268-
|{ DraftToken.Kind= LexerSymbolKind.Ident; Token= t1}::{Kind= LexerSymbolKind.Operator; Token= t2}:: remainingTokens->
269-
if t2.Tag= FSharpTokenTag.DOTthen
270-
tryFindStartColumn remainingTokens
271-
else
272-
Some t1.LeftColumn
273-
|{ Kind= LexerSymbolKind.Ident; Token= t}::_->
274-
Some t.LeftColumn
275-
|_::_|[]->
276-
None
277-
letdecreasingTokens=
278-
match tokensUnderCursor|> List.sortBy(fun token->- token.Token.LeftColumn)with
279-
// Skip the first dot if it is the start of the identifier
280-
|{Kind= LexerSymbolKind.Operator; Token= t}:: remainingTokenswhen t.Tag= FSharpTokenTag.DOT->
281-
remainingTokens
282-
| newTokens-> newTokens
255+
letrightColumnCorrection=
256+
match lookupKindwith
257+
| SymbolLookupKind.Precise->0
258+
| SymbolLookupKind.Greedy->1
283259

284-
match decreasingTokenswith
285-
|[]-> None
286-
| first::_->
287-
tryFindStartColumn decreasingTokens
288-
|> Option.map(fun leftCol->
289-
{ Kind= LexerSymbolKind.Ident
290-
Line= linePos.Line
291-
LeftColumn= leftCol
292-
RightColumn= first.RightColumn+1
293-
Text= lineStr.[leftCol..first.RightColumn]
294-
FileName= fileName})
295-
| SymbolLookupKind.Fuzzy
296-
| SymbolLookupKind.ByRightColumn->
297-
// Select IDENT token. If failed, select OPERATOR token.
298-
tokensUnderCursor
299-
|> List.tryFind(fun{DraftToken.Kind=k}->
300-
match kwith
301-
| LexerSymbolKind.Ident
302-
| LexerSymbolKind.GenericTypeParameter
303-
| LexerSymbolKind.StaticallyResolvedTypeParameter->true
304-
|_->false)
305-
|> Option.orElseWith(fun _-> tokensUnderCursor|> List.tryFind(fun{DraftToken.Kind=k}-> k= LexerSymbolKind.Operator))
306-
|> Option.map(fun token->
307-
{ Kind= token.Kind
308-
Line= linePos.Line
309-
LeftColumn= token.Token.LeftColumn
310-
RightColumn= token.RightColumn+1
311-
Text= lineStr.Substring(token.Token.LeftColumn, token.Token.FullMatchedLength)
312-
FileName= fileName})
260+
tokens|> List.filter(fun x-> x.Token.LeftColumn<= linePos.Character&&(x.RightColumn+ rightColumnCorrection)>= linePos.Character)
261+
262+
// Select IDENT token. If failed, select OPERATOR token.
263+
tokensUnderCursor
264+
|> List.tryFind(fun{DraftToken.Kind=k}->
265+
match kwith
266+
| LexerSymbolKind.Ident
267+
| LexerSymbolKind.GenericTypeParameter
268+
| LexerSymbolKind.StaticallyResolvedTypeParameter->true
269+
|_->false)
270+
|> Option.orElseWith(fun _-> tokensUnderCursor|> List.tryFind(fun{DraftToken.Kind=k}-> k= LexerSymbolKind.Operator))
271+
|> Option.map(fun token->
272+
letplid,_= QuickParse.GetPartialLongNameEx(lineStr, token.RightColumn)
273+
letidentStr= lineStr.Substring(token.Token.LeftColumn, token.Token.FullMatchedLength)
274+
{ Kind= token.Kind
275+
Ident=
276+
Ident
277+
(identStr,
278+
Range.mkRange
279+
fileName
280+
(Range.mkPos(linePos.Line+1) token.Token.LeftColumn)
281+
(Range.mkPos(linePos.Line+1)(token.RightColumn+1)))
282+
FullIsland= plid@[identStr]})
313283

314284
letprivategetCachedSourceLineData(documentKey:DocumentId,sourceText:SourceText,position:int,fileName:string,defines:string list)=
315285
lettextLine= sourceText.Lines.GetLineFromPosition(position)

‎vsintegration/src/FSharp.Editor/Common/Pervasive.fs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,13 @@ type AsyncBuilder with
211211

212212
moduleOption=
213213
letguard(x:bool):Option<unit>=
214-
if xthen Some()else None
214+
if xthen Some()else None
215+
216+
moduleList=
217+
letfoldi(folder:'State->int->'T->'State)(state:'State)(xs:'T list)=
218+
let mutablestate= state
219+
let mutablei=0
220+
for xin xsdo
221+
state<- folder state i x
222+
i<- i+1
223+
state

‎vsintegration/src/FSharp.Editor/Common/SymbolHelpers.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ module internal SymbolHelpers =
7070
do! Option.guard(originalText.Length>0)
7171
let!options= projectInfoManager.TryGetOptionsForEditingDocumentOrProject document
7272
letdefines= CompilerEnvironment.GetCompilationDefinesForEditing(document.Name, options.OtherOptions|> Seq.toList)
73-
let!symbol= CommonHelpers.getSymbolAtPosition(document.Id, sourceText, symbolSpan.Start, document.FilePath, defines, SymbolLookupKind.Fuzzy)
73+
let!symbol= CommonHelpers.getSymbolAtPosition(document.Id, sourceText, symbolSpan.Start, document.FilePath, defines, SymbolLookupKind.Greedy)
7474
let!_,_,checkFileResults= checker.ParseAndCheckDocument(document, options, allowStaleResults=true)
7575
lettextLine= sourceText.Lines.GetLineFromPosition(symbolSpan.Start)
7676
lettextLinePos= sourceText.Lines.GetLinePosition(symbolSpan.Start)
7777
letfcsTextLineNumber= textLinePos.Line+1
78-
let!symbolUse= checkFileResults.GetSymbolUseAtLocation(fcsTextLineNumber, symbol.RightColumn, textLine.Text.ToString(),[symbol.Text])
78+
let!symbolUse= checkFileResults.GetSymbolUseAtLocation(fcsTextLineNumber, symbol.Ident.idRange.EndColumn, textLine.Text.ToString(), symbol.FullIsland)
7979
let!declLoc= symbolUse.GetDeclarationLocation(document)
8080
letnewText= textChanger originalText
8181
// defer finding all symbol uses throughout the solution

‎vsintegration/src/FSharp.Editor/DocumentHighlights/DocumentHighlightsService.fs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ type internal FSharpDocumentHighlightsService [<ImportingConstructor>] (checkerP
5757
lettextLine= sourceText.Lines.GetLineFromPosition(position)
5858
lettextLinePos= sourceText.Lines.GetLinePosition(position)
5959
letfcsTextLineNumber= textLinePos.Line+1
60-
let!symbol= CommonHelpers.getSymbolAtPosition(documentKey, sourceText, position, filePath, defines, SymbolLookupKind.Fuzzy)
60+
let!symbol= CommonHelpers.getSymbolAtPosition(documentKey, sourceText, position, filePath, defines, SymbolLookupKind.Greedy)
6161
let!_,_,checkFileResults= checker.ParseAndCheckDocument(filePath, textVersionHash, sourceText.ToString(), options, allowStaleResults=true)
62-
let!symbolUse= checkFileResults.GetSymbolUseAtLocation(fcsTextLineNumber, symbol.RightColumn, textLine.ToString(),[symbol.Text])
62+
let!symbolUse= checkFileResults.GetSymbolUseAtLocation(fcsTextLineNumber, symbol.Ident.idRange.EndColumn, textLine.ToString(), symbol.FullIsland)
6363
let!symbolUses= checkFileResults.GetUsesOfSymbolInFile(symbolUse.Symbol)|> liftAsync
6464
return
6565
[|for symbolUsein symbolUsesdo
6666
yield{ IsDefinition= symbolUse.IsFromDefinition
6767
TextSpan= CommonRoslynHelpers.FSharpRangeToTextSpan(sourceText, symbolUse.RangeAlternate)}|]
68-
|> fixInvalidSymbolSpans sourceText symbol.Text
68+
|> fixInvalidSymbolSpans sourceText symbol.Ident.idText
6969
}
7070

7171
interface IDocumentHighlightsServicewith

‎vsintegration/src/FSharp.Editor/InlineRename/InlineRenameService.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ type internal InlineRenameService
150150
lettextLine= sourceText.Lines.GetLineFromPosition(position)
151151
lettextLinePos= sourceText.Lines.GetLinePosition(position)
152152
letfcsTextLineNumber= textLinePos.Line+1// Roslyn line numbers are zero-based, FSharp.Compiler.Service line numbers are 1-based
153-
let!symbol= CommonHelpers.getSymbolAtPosition(document.Id, sourceText, position, document.FilePath, defines, SymbolLookupKind.Fuzzy)
153+
let!symbol= CommonHelpers.getSymbolAtPosition(document.Id, sourceText, position, document.FilePath, defines, SymbolLookupKind.Greedy)
154154
let!_,_,checkFileResults= checker.ParseAndCheckDocument(document, options, allowStaleResults=true)
155-
let!symbolUse= checkFileResults.GetSymbolUseAtLocation(fcsTextLineNumber, symbol.RightColumn, textLine.Text.ToString(),[symbol.Text])
155+
let!symbolUse= checkFileResults.GetSymbolUseAtLocation(fcsTextLineNumber, symbol.Ident.idRange.EndColumn, textLine.Text.ToString(), symbol.FullIsland)
156156
let!declLoc= symbolUse.GetDeclarationLocation(document)
157157
return InlineRenameInfo(checker, projectInfoManager, document, sourceText, symbolUse, declLoc, checkFileResults):> IInlineRenameInfo
158158
}

‎vsintegration/src/FSharp.Editor/Navigation/FindReferencesService.fs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ type internal FSharpFindReferencesService
6060
letlineNumber= sourceText.Lines.GetLinePosition(position).Line+1
6161
letdefines= CompilerEnvironment.GetCompilationDefinesForEditing(document.FilePath, options.OtherOptions|> Seq.toList)
6262

63-
let!symbol= CommonHelpers.getSymbolAtPosition(document.Id, sourceText, position, document.FilePath, defines, SymbolLookupKind.Fuzzy)
64-
let!symbolUse= checkFileResults.GetSymbolUseAtLocation(lineNumber, symbol.RightColumn, textLine,[symbol.Text])
65-
let!declaration= checkFileResults.GetDeclarationLocationAlternate(lineNumber, symbol.RightColumn, textLine,[symbol.Text],false)|> liftAsync
63+
let!symbol= CommonHelpers.getSymbolAtPosition(document.Id, sourceText, position, document.FilePath, defines, SymbolLookupKind.Greedy)
64+
let!symbolUse= checkFileResults.GetSymbolUseAtLocation(lineNumber, symbol.Ident.idRange.EndColumn, textLine, symbol.FullIsland)
65+
let!declaration= checkFileResults.GetDeclarationLocationAlternate(lineNumber, symbol.Ident.idRange.EndColumn, textLine, symbol.FullIsland,false)|> liftAsync
6666
lettags= GlyphTags.GetTags(CommonRoslynHelpers.GetGlyphForSymbol symbolUse.Symbol)
6767

6868
letdeclarationRange=
@@ -82,12 +82,12 @@ type internal FSharpFindReferencesService
8282
|[]->
8383
[ DefinitionItem.CreateNonNavigableItem(
8484
tags,
85-
ImmutableArray.Create(TaggedText(TextTags.Text, symbol.Text)),
85+
ImmutableArray.Create(TaggedText(TextTags.Text, symbol.Ident.idText)),
8686
ImmutableArray.Create(TaggedText(TextTags.Assembly, symbolUse.Symbol.Assembly.SimpleName)))]
8787
|_->
8888
declarationSpans
8989
|> List.map(fun span->
90-
DefinitionItem.Create(tags, ImmutableArray.Create(TaggedText(TextTags.Text, symbol.Text)), span))
90+
DefinitionItem.Create(tags, ImmutableArray.Create(TaggedText(TextTags.Text, symbol.Ident.idText)), span))
9191
}|> liftAsync
9292

9393
for definitionItemin definitionItemsdo

‎vsintegration/src/FSharp.Editor/Navigation/GoToDefinitionService.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ type internal FSharpGoToDefinitionService
4747
lettextLine= sourceText.Lines.GetLineFromPosition(position)
4848
lettextLinePos= sourceText.Lines.GetLinePosition(position)
4949
letfcsTextLineNumber= textLinePos.Line+1// Roslyn line numbers are zero-based, FSharp.Compiler.Service line numbers are 1-based
50-
let!symbol= CommonHelpers.getSymbolAtPosition(documentKey, sourceText, position, filePath, defines, SymbolLookupKind.Fuzzy)
50+
let!symbol= CommonHelpers.getSymbolAtPosition(documentKey, sourceText, position, filePath, defines, SymbolLookupKind.Greedy)
5151
let!_,_,checkFileResults= checker.ParseAndCheckDocument(filePath, textVersionHash, sourceText.ToString(), options, allowStaleResults=true)
52-
let!declarations= checkFileResults.GetDeclarationLocationAlternate(fcsTextLineNumber, symbol.RightColumn, textLine.ToString(),[symbol.Text],false)|> liftAsync
52+
let!declarations= checkFileResults.GetDeclarationLocationAlternate(fcsTextLineNumber, symbol.Ident.idRange.EndColumn, textLine.ToString(), symbol.FullIsland,false)|> liftAsync
5353

5454
match declarationswith
5555
| FSharpFindDeclResult.DeclFound(range)->return range

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp