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

Commit94c7fe1

Browse files
cartermpTIHan
authored andcommitted
Do not trigger completion on operators (#4054)
* No triggered completion on operators* Check with classification data instead of stupid custom stuff* Fix silly tests* Feedback
1 parent6e8515f commit94c7fe1

File tree

3 files changed

+88
-10
lines changed

3 files changed

+88
-10
lines changed

‎vsintegration/src/FSharp.Editor/Completion/CompletionProvider.fs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,17 @@ type internal FSharpCompletionProvider
8484
// Skip if we are not on a completion trigger
8585
else
8686
lettriggerPosition= caretPosition-1
87-
letc= sourceText.[triggerPosition]
87+
lettriggerChar= sourceText.[triggerPosition]
88+
letprevChar= sourceText.[triggerPosition-1]
8889

8990
// do not trigger completion if it's not single dot, i.e. range expression
90-
ifnot Settings.IntelliSense.ShowAfterCharIsTyped&&sourceText.[triggerPosition-1]='.'then
91+
ifnot Settings.IntelliSense.ShowAfterCharIsTyped&&prevChar='.'then
9192
false
92-
93-
// Trigger completion if we are on a valid classification type
9493
else
9594
letdocumentId,filePath,defines= getInfo()
9695
CompletionUtils.shouldProvideCompletion(documentId, filePath, defines, sourceText, triggerPosition)&&
97-
(c='.'||(Settings.IntelliSense.ShowAfterCharIsTyped&& CompletionUtils.isStartingNewWord(sourceText, triggerPosition)))
96+
(triggerChar='.'||(Settings.IntelliSense.ShowAfterCharIsTyped&& CompletionUtils.isStartingNewWord(sourceText, triggerPosition)))
97+
9898

9999
static memberProvideCompletionsAsyncAux(checker:FSharpChecker,sourceText:SourceText,caretPosition:int,options:FSharpProjectOptions,filePath:string,
100100
textVersionHash:int,getAllSymbols:unit->AssemblySymbol list)=

‎vsintegration/src/FSharp.Editor/Completion/CompletionUtils.fs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,19 @@ module internal CompletionUtils =
8282
letisStartingNewWord(sourceText,position)=
8383
CommonCompletionUtilities.IsStartingNewWord(sourceText, position,(fun ch-> isIdentifierStartCharacter ch),(fun ch-> isIdentifierPartCharacter ch))
8484

85-
letshouldProvideCompletion(documentId:DocumentId,filePath:string,defines:string list,text:SourceText,position:int):bool=
86-
lettextLines=text.Lines
87-
lettriggerLine= textLines.GetLineFromPositionposition
88-
letcolorizationData= Tokenizer.getColorizationData(documentId,text, triggerLine.Span, Some filePath, defines, CancellationToken.None)
85+
letshouldProvideCompletion(documentId:DocumentId,filePath:string,defines:string list,sourceText:SourceText,triggerPosition:int):bool=
86+
lettextLines=sourceText.Lines
87+
lettriggerLine= textLines.GetLineFromPositiontriggerPosition
88+
letcolorizationData= Tokenizer.getColorizationData(documentId,sourceText, triggerLine.Span, Some filePath, defines, CancellationToken.None)
8989
colorizationData.Count=0||// we should provide completion at the start of empty line, where there are no tokens at all
9090
colorizationData.Exists(fun classifiedSpan->
91-
classifiedSpan.TextSpan.IntersectsWithposition&&
91+
classifiedSpan.TextSpan.IntersectsWithtriggerPosition&&
9292
(
9393
match classifiedSpan.ClassificationTypewith
9494
| ClassificationTypeNames.Comment
9595
| ClassificationTypeNames.StringLiteral
9696
| ClassificationTypeNames.ExcludedCode
97+
| ClassificationTypeNames.Operator
9798
| ClassificationTypeNames.NumericLiteral->false
9899
|_->true// anything else is a valid classification type
99100
))

‎vsintegration/tests/unittests/CompletionProviderTests.fs‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,83 @@ System.Console.WriteLine()
196196
lettriggered= FSharpCompletionProvider.ShouldTriggerCompletionAux(SourceText.From(fileContents), caretPosition, CompletionTriggerKind.Insertion, getInfo)
197197
Assert.IsFalse(triggered,"FSharpCompletionProvider.ShouldTriggerCompletionAux() should not trigger")
198198

199+
[<Test>]
200+
letShouldNotTriggerCompletionInOperatorWithDot()=
201+
// Simulate mistyping '|>' as '|.'
202+
letfileContents="""
203+
let f() =
204+
12.0 |. sqrt
205+
"""
206+
letcaretPosition= fileContents.IndexOf("|.")
207+
letdocumentId= DocumentId.CreateNewId(ProjectId.CreateNewId())
208+
letgetInfo()= documentId, filePath,[]
209+
lettriggered= FSharpCompletionProvider.ShouldTriggerCompletionAux(SourceText.From(fileContents), caretPosition, CompletionTriggerKind.Insertion, getInfo)
210+
Assert.IsFalse(triggered,"FSharpCompletionProvider.ShouldTriggerCompletionAux() should not trigger on operators")
211+
212+
[<Test>]
213+
letShouldTriggerCompletionInAttribute()=
214+
letfileContents="""
215+
[<A
216+
module Foo = module end
217+
"""
218+
letmarker="A"
219+
letcaretPosition= fileContents.IndexOf(marker)+ marker.Length
220+
letdocumentId= DocumentId.CreateNewId(ProjectId.CreateNewId())
221+
letgetInfo()= documentId, filePath,[]
222+
lettriggered= FSharpCompletionProvider.ShouldTriggerCompletionAux(SourceText.From(fileContents), caretPosition, CompletionTriggerKind.Insertion, getInfo)
223+
Assert.IsTrue(triggered,"Completion should trigger on Attributes.")
224+
225+
[<Test>]
226+
letShouldTriggerCompletionAfterDerefOperator()=
227+
letfileContents="""
228+
let foo = ref 12
229+
printfn "%d" !f
230+
"""
231+
letmarker="!f"
232+
letcaretPosition= fileContents.IndexOf(marker)+ marker.Length
233+
letdocumentId= DocumentId.CreateNewId(ProjectId.CreateNewId())
234+
letgetInfo()= documentId, filePath,[]
235+
lettriggered= FSharpCompletionProvider.ShouldTriggerCompletionAux(SourceText.From(fileContents), caretPosition, CompletionTriggerKind.Insertion, getInfo)
236+
Assert.IsTrue(triggered,"Completion should trigger after typing an identifier that follows a dereference operator (!).")
237+
238+
[<Test>]
239+
letShouldTriggerCompletionAfterAddressOfOperator()=
240+
letfileContents="""
241+
type Point = { mutable X: int; mutable Y: int }
242+
let pnt = { X = 1; Y = 2 }
243+
use ptr = fixed &p
244+
"""
245+
letmarker="&p"
246+
letcaretPosition= fileContents.IndexOf(marker)+ marker.Length
247+
letdocumentId= DocumentId.CreateNewId(ProjectId.CreateNewId())
248+
letgetInfo()= documentId, filePath,[]
249+
lettriggered= FSharpCompletionProvider.ShouldTriggerCompletionAux(SourceText.From(fileContents), caretPosition, CompletionTriggerKind.Insertion, getInfo)
250+
Assert.IsTrue(triggered,"Completion should trigger after typing an identifier that follows an addressOf operator (&).")
251+
252+
[<Test>]
253+
letShouldTriggerCompletionAfterArithmeticOperation()=
254+
letfileContents="""
255+
let xVal = 1.0
256+
let yVal = 2.0
257+
let zVal
258+
259+
xVal+y
260+
xVal-y
261+
xVal*y
262+
xVal/y
263+
xVal%y
264+
xVal**y
265+
"""
266+
267+
letmarkers=["+y";"-y";"*y";"/y";"%y";"**y"]
268+
269+
for markerin markersdo
270+
letcaretPosition= fileContents.IndexOf(marker)+ marker.Length
271+
letdocumentId= DocumentId.CreateNewId(ProjectId.CreateNewId())
272+
letgetInfo()= documentId, filePath,[]
273+
lettriggered= FSharpCompletionProvider.ShouldTriggerCompletionAux(SourceText.From(fileContents), caretPosition, CompletionTriggerKind.Insertion, getInfo)
274+
Assert.IsTrue(triggered,"Completion should trigger after typing an identifier that follows a mathematical operation")
275+
199276
[<Test>]
200277
letShouldDisplayTypeMembers()=
201278
letfileContents="""

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp