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

Commit0e6614e

Browse files
dungpaKevinRansom
authored andcommitted
Refactor help context service (dotnet#2059)
1 parentcd501e1 commit0e6614e

File tree

1 file changed

+50
-55
lines changed

1 file changed

+50
-55
lines changed

‎vsintegration/src/FSharp.Editor/Commands/HelpContextService.fs‎

Lines changed: 50 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -46,65 +46,63 @@ type internal FSharpHelpContextService
4646
content="."->true
4747
|_->false
4848

49-
letkeyword=
50-
lettokenInformation,col=
51-
letcol=
52-
if caretColumn= lineText.Length&& caretColumn>0then
53-
// if we are at the end of the line, we always step back one character
54-
caretColumn-1
55-
else
56-
caretColumn
49+
lettokenInformation,col=
50+
letcol=
51+
if caretColumn= lineText.Length&& caretColumn>0then
52+
// if we are at the end of the line, we always step back one character
53+
caretColumn-1
54+
else
55+
caretColumn
5756

58-
letgetTokenAt line col=
59-
if col<0|| line<0then Noneelse
60-
letstart= textLines.[line].Start+ col
61-
letspan= TextSpan.FromBounds(start, start+1)
62-
tokens
63-
|> Seq.tryFindIndex(fun t-> t.TextSpan.Contains(span))
64-
|> Option.map(fun i-> tokens.[i])
57+
letgetTokenAt line col=
58+
if col<0|| line<0then Noneelse
59+
letstart= textLines.[line].Start+ col
60+
letspan= TextSpan.FromBounds(start, start+1)
61+
tokens
62+
|> Seq.tryFindIndex(fun t-> t.TextSpan.Contains(span))
63+
|> Option.map(fun i-> tokens.[i])
6564

66-
match getTokenAt line colwith
67-
| Some tas original->// when col > 0 && shouldTryToFindSurroundingIdent t ->
68-
if shouldTryToFindSurroundingIdent tthen
69-
match getTokenAt line(col-1)with
70-
| Some tas newInfowhennot(shouldTryToFindSurroundingIdent t)-> newInfo, col-1
71-
|_->
65+
match getTokenAt line colwith
66+
| Some tas original->// when col > 0 && shouldTryToFindSurroundingIdent t ->
67+
if shouldTryToFindSurroundingIdent tthen
68+
match getTokenAt line(col-1)with
69+
| Some tas newInfowhennot(shouldTryToFindSurroundingIdent t)-> newInfo, col-1
70+
|_->
7271
match getTokenAt line(col+1)with
7372
| Some tas newInfowhennot(shouldTryToFindSurroundingIdent t)-> newInfo, col+1
7473
|_-> original, col
75-
else original, col
76-
| otherwise-> otherwise, col
74+
else original, col
75+
| otherwise-> otherwise, col
7776

78-
match tokenInformationwith
79-
| None-> None
80-
| Some token->
81-
match token.ClassificationTypewith
82-
| ClassificationTypeNames.Keyword
83-
| ClassificationTypeNames.Operator
84-
| ClassificationTypeNames.PreprocessorKeyword->
85-
sourceText.GetSubText(token.TextSpan).ToString()+"_FS"|> Some
86-
| ClassificationTypeNames.Comment-> Some"comment_FS"
87-
| ClassificationTypeNames.Identifier->
88-
try
89-
letpossibleIdentifier= QuickParse.GetCompleteIdentifierIslandfalse lineText col
90-
match possibleIdentifierwith
91-
| None-> None
92-
| Some(s,colAtEndOfNames,_)->
93-
if check.HasFullTypeCheckInfothen
94-
letqualId= PrettyNaming.GetLongNameFromString s
95-
check.GetF1KeywordAlternate(Line.fromZ line, colAtEndOfNames, lineText, qualId)
96-
|> Async.RunSynchronously
97-
else None
98-
with e->
99-
Assert.Exception(e)
100-
reraise()
101-
|_-> None
102-
return keyword
77+
match tokenInformationwith
78+
| None->return None
79+
| Some token->
80+
match token.ClassificationTypewith
81+
| ClassificationTypeNames.Keyword
82+
| ClassificationTypeNames.Operator
83+
| ClassificationTypeNames.PreprocessorKeyword->
84+
return Some(sourceText.GetSubText(token.TextSpan).ToString()+"_FS")
85+
| ClassificationTypeNames.Comment->return Some"comment_FS"
86+
| ClassificationTypeNames.Identifier->
87+
try
88+
letpossibleIdentifier= QuickParse.GetCompleteIdentifierIslandfalse lineText col
89+
match possibleIdentifierwith
90+
| None->return None
91+
| Some(s,colAtEndOfNames,_)->
92+
if check.HasFullTypeCheckInfothen
93+
letqualId= PrettyNaming.GetLongNameFromString s
94+
return! check.GetF1KeywordAlternate(Line.fromZ line, colAtEndOfNames, lineText, qualId)
95+
else
96+
return None
97+
with e->
98+
Assert.Exception e
99+
return None
100+
|_->return None
103101
}
104102

105103
interface IHelpContextServicewith
106-
memberthis.Languagewith get()="fsharp"
107-
memberthis.Productwith get()="fsharp"
104+
memberthis.Language="fsharp"
105+
memberthis.Product="fsharp"
108106

109107
memberthis.GetHelpTermAsync(document,textSpan,cancellationToken)=
110108
async{
@@ -116,11 +114,8 @@ type internal FSharpHelpContextService
116114
lettextLine= sourceText.Lines.GetLineFromPosition(textSpan.Start)
117115
lettokens= CommonHelpers.getColorizationData(document.Id, sourceText, textLine.Span, Some document.Name, defines, cancellationToken)
118116
let!keyword= FSharpHelpContextService.GetHelpTerm(checkerProvider.Checker, sourceText, document.FilePath, options, textSpan, tokens, textVersion.GetHashCode())
119-
120-
returnmatch keywordwith
121-
| Some k-> k
122-
| None->""
123-
| None->return""
117+
return defaultArg keyword String.Empty
118+
| None->return String.Empty
124119
}|> CommonRoslynHelpers.StartAsyncAsTask cancellationToken
125120

126121
memberthis.FormatSymbol(_symbol)= Unchecked.defaultof<_>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp