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

Commit7ee4c7f

Browse files
forkiKevinRansom
authored andcommitted
Don't suggest things when the entered identifier is in scope (dotnet#2218)
* Don't suggest things when they are in scope* Don't suggest things when they are in scope* Use id as term* cleanup namespaces* Proper suggestion of double tick identifiers -fixesdotnet#2217* Do not suggest operators
1 parentd1d9bab commit7ee4c7f

File tree

8 files changed

+64
-21
lines changed

8 files changed

+64
-21
lines changed

‎src/fsharp/CompileOps.fs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,9 @@ let getErrorString key = SR.GetString key
609609

610610
let(|InvalidArgument|_|)(exn:exn)=match exnwith:? ArgumentExceptionas e-> Some e.Message|_-> None
611611

612-
letOutputPhasedErrorR errorStyle(os:System.Text.StringBuilder)(err:PhasedDiagnostic)=
613-
let recOutputExceptionR(os:System.Text.StringBuilder)=function
612+
letOutputPhasedErrorR errorStyle(os:StringBuilder)(err:PhasedDiagnostic)=
613+
let recOutputExceptionR(os:StringBuilder)error=
614+
match errorwith
614615
| ConstraintSolverTupleDiffLengths(_,tl1,tl2,m,m2)->
615616
os.Append(ConstraintSolverTupleDiffLengthsE().Format tl1.Length tl2.Length)|> ignore
616617
if m.StartLine<> m2.StartLinethen

‎src/fsharp/ErrorResolutionHints.fs‎

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,51 @@
33
/// Functions to format error message details
44
moduleinternalMicrosoft.FSharp.Compiler.ErrorResolutionHints
55

6+
openInternal.Utilities
7+
68
letmaxSuggestions=5
79
letminThresholdForSuggestions=0.7
810
lethighConfidenceThreshold=0.85
911
letminStringLengthForThreshold=3
1012

1113
/// We report a candidate if its edit distance is <= the threshold.
12-
/// The threshhold is set to about a quarter of the number of characters the user entered.
13-
letIsInEditDistanceProximityuserEntered suggestion=
14-
leteditDistance=Internal.Utilities.EditDistance.CalcEditDistance(userEntered,suggestion)
14+
/// The threshhold is set to about a quarter of the number of characters.
15+
letIsInEditDistanceProximityidText suggestion=
16+
leteditDistance= EditDistance.CalcEditDistance(idText,suggestion)
1517
letthreshold=
16-
matchuserEntered.Lengthwith
18+
matchidText.Lengthwith
1719
| xwhen x<5->1
1820
| xwhen x<7->2
1921
| x-> x/4+1
2022

2123
editDistance<= threshold
2224

2325
/// Filters predictions based on edit distance to the given unknown identifier.
24-
letFilterPredictions(userEntered:string)(suggestionF:ErrorLogger.Suggestions)=
25-
letuppercaseText= userEntered.ToUpperInvariant()
26-
suggestionF()
26+
letFilterPredictions(idText:string)(suggestionF:ErrorLogger.Suggestions)=
27+
letuppercaseText= idText.ToUpperInvariant()
28+
letallSuggestions= suggestionF()
29+
30+
letdemangle(nm:string)=
31+
if nm.StartsWith"("&& nm.EndsWith" )"then
32+
letcleanName= nm.[2..nm.Length-3]
33+
cleanName
34+
else nm
35+
36+
/// Returns `true` if given string is an operator display name, e.g. ( |>> )
37+
letIsOperatorName(name:string)=
38+
ifnot(name.StartsWith"("&& name.EndsWith" )")thenfalseelse
39+
letname= name.[2..name.Length-3]
40+
letres= name|> Seq.forall(fun c-> c<>' ')
41+
res
42+
43+
if allSuggestions.Contains idTextthen[]else// some other parsing error occurred
44+
allSuggestions
2745
|> Seq.choose(fun suggestion->
28-
if suggestion= userEnteredthen Noneelse
46+
if IsOperatorName suggestionthen Noneelse
47+
letsuggestion:string= demangle suggestion
2948
letsuggestedText= suggestion.ToUpperInvariant()
30-
letsimilarity=Internal.Utilities.EditDistance.JaroWinklerDistance uppercaseText suggestedText
31-
if similarity>= highConfidenceThreshold|| suggestion.EndsWith("."+userEntered)then
49+
letsimilarity= EditDistance.JaroWinklerDistance uppercaseText suggestedText
50+
if similarity>= highConfidenceThreshold|| suggestion.EndsWith("."+idText)then
3251
Some(similarity,suggestion)
3352
elif similarity< minThresholdForSuggestions&& suggestedText.Length> minStringLengthForThresholdthen
3453
None

‎src/fsharp/NameResolution.fs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2303,6 +2303,13 @@ let rec ResolveExprLongIdentPrim sink (ncenv:NameResolver) fullyQualified m ad n
23032303
|> Seq.map(fun e-> e.Value.DisplayName)
23042304
|> Set.ofSeq
23052305

2306+
letsuggestedModulesAndNamespaces=
2307+
nenv.ModulesAndNamespaces fullyQualified
2308+
|> Seq.collect(fun kv-> kv.Value)
2309+
|> Seq.filter(fun modref-> IsEntityAccessible ncenv.amap m ad modref)
2310+
|> Seq.collect(fun e->[e.DisplayName; e.DemangledModuleOrNamespaceName])
2311+
|> Set.ofSeq
2312+
23062313
letunions=
23072314
// check if the user forgot to use qualified access
23082315
nenv.eTyconsByDemangledNameAndArity
@@ -2320,6 +2327,7 @@ let rec ResolveExprLongIdentPrim sink (ncenv:NameResolver) fullyQualified m ad n
23202327

23212328
suggestedNames
23222329
|> Set.union suggestedTypes
2330+
|> Set.union suggestedModulesAndNamespaces
23232331
|> Set.union unions
23242332

23252333
raze(UndefinedName(0,FSComp.SR.undefinedNameValueOfConstructor,id,suggestNamesAndTypes))
@@ -2407,7 +2415,7 @@ let rec ResolveExprLongIdentPrim sink (ncenv:NameResolver) fullyQualified m ad n
24072415

24082416
search+++ moduleSearch+++ tyconSearch
24092417

2410-
letsuggestEverythingInScope()=
2418+
letsuggestEverythingInScope()=
24112419
letsuggestedModulesAndNamespaces=
24122420
nenv.ModulesAndNamespaces fullyQualified
24132421
|> Seq.collect(fun kv-> kv.Value)

‎tests/fsharp/typecheck/sigs/neg06.bsl‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,27 +93,27 @@ neg06.fs(128,53,128,61): typecheck error FS0043: A type parameter is missing a c
9393

9494
neg06.fs(141,10,141,18): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct fieldor inheritance relation
9595

96-
neg06.fs(148,13,148,21): typecheck error FS0039: The valueor constructor 'BadType1' isnot defined. Maybe you want one of the following: BadType0
96+
neg06.fs(148,13,148,21): typecheck error FS0039: The valueor constructor 'BadType1' isnot defined.
9797

9898
neg06.fs(150,10,150,18): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct fieldor inheritance relation
9999

100-
neg06.fs(157,13,157,21): typecheck error FS0039: The valueor constructor 'BadType2' isnot defined. Maybe you want one of the following: BadType0, BadType1
100+
neg06.fs(157,13,157,21): typecheck error FS0039: The valueor constructor 'BadType2' isnot defined.
101101

102102
neg06.fs(159,10,159,18): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct fieldor inheritance relation
103103

104-
neg06.fs(166,13,166,21): typecheck error FS0039: The valueor constructor 'BadType3' isnot defined. Maybe you want one of the following: BadType0, BadType1, BadType2
104+
neg06.fs(166,13,166,21): typecheck error FS0039: The valueor constructor 'BadType3' isnot defined.
105105

106106
neg06.fs(195,10,195,18): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct fieldor inheritance relation
107107

108108
neg06.fs(203,13,203,21): typecheck error FS0039: The valueor constructor 'BadType1' isnot defined.
109109

110110
neg06.fs(205,10,205,18): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct fieldor inheritance relation
111111

112-
neg06.fs(213,13,213,21): typecheck error FS0039: The valueor constructor 'BadType2' isnot defined. Maybe you want one of the following: BadType1
112+
neg06.fs(213,13,213,21): typecheck error FS0039: The valueor constructor 'BadType2' isnot defined.
113113

114114
neg06.fs(215,10,215,18): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct fieldor inheritance relation
115115

116-
neg06.fs(223,13,223,21): typecheck error FS0039: The valueor constructor 'BadType3' isnot defined. Maybe you want one of the following: BadType1, BadType2
116+
neg06.fs(223,13,223,21): typecheck error FS0039: The valueor constructor 'BadType3' isnot defined.
117117

118118
neg06.fs(294,10,294,12): typecheck error FS0009: Uses of this construct may resultin the generation of unverifiable .NET IL code. This warning can be disabled using '--nowarn:9'or '#nowarn"9"'.
119119

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// #Warnings
2+
//<Expects status="Error" id="FS0599">Missing qualification after '.'</Expects>
3+
4+
moduleN=
5+
letname="hallo"
6+
7+
typeT=
8+
static membermyMember=1
9+
10+
letx= N.
11+
12+
13+
exit0

‎tests/fsharpqa/Source/Warnings/SuggestDoubleBacktickIdentifiers.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// #Warnings
2-
//<Expects status="Error" span="(7,11,7,25)">The value, constructor, namespace or type 'longe name' is not defined.</Expects>
2+
//<Expects status="Error" span="(7,11,7,25)">The value, constructor, namespace or type 'longe name' is not defined. Maybe you want one of the following: longer name$</Expects>
33

44
moduleN=
55
let``longer name``="hallo"

‎tests/fsharpqa/Source/Warnings/env.lst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
SOURCE=DontSuggestCompletelyWrongStuff.fs SCFLAGS="--vserrors" # DontSuggestCompletelyWrongStuff.fs
3939
SOURCE=SuggestTypesInNamespaceVS.fs SCFLAGS="--vserrors" # SuggestTypesInNamespaceVS.fs
4040
SOURCE=SuggestAsyncModule.fs SCFLAGS="--vserrors" # SuggestAsyncModule.fs
41+
SOURCE=DontSuggestWhenThingsAreOpen.fs SCFLAGS="--vserrors" # DontSuggestWhenThingsAreOpen.fs
4142
SOURCE=SuggestDoubleBacktickIdentifiers.fs SCFLAGS="--vserrors" # SuggestDoubleBacktickIdentifiers.fs
4243
SOURCE=ElseBranchHasWrongType.fs # ElseBranchHasWrongType.fs
4344
SOURCE=ElseBranchHasWrongType2.fs # ElseBranchHasWrongType2.fs

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,17 @@ type internal FSharpReplaceWithSuggestionCodeFixProvider() =
4040
letparts= message.Split([| maybeString|], StringSplitOptions.None)
4141
if parts.Length>1then
4242
letsuggestions=
43-
parts.[1].Split([|' ';'\r';'\n'|], StringSplitOptions.RemoveEmptyEntries)
43+
parts.[1].Split([|'\r';'\n'|], StringSplitOptions.RemoveEmptyEntries)
4444
|> Array.map(fun s-> s.Trim())
4545

4646
letdiagnostics=[| diagnostic|].ToImmutableArray()
4747

4848
for suggestionin suggestionsdo
49+
letreplacement=if suggestion.Contains""then"``"+ suggestion+"``"else suggestion
4950
letcodefix=
5051
createCodeFix(
5152
FSComp.SR.replaceWithSuggestion suggestion,
5253
context,
53-
TextChange(context.Span,suggestion))
54+
TextChange(context.Span,replacement))
5455
context.RegisterCodeFix(codefix, diagnostics))
5556
}|> CommonRoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp