Skip to content

Do not trigger completion on operators - #4054

Merged
TIHan merged 4 commits into
dotnet:masterfrom
cartermp:no-trigger-op
Dec 6, 2017
Merged

TIHan merged 4 commits into
dotnet:masterfrom
cartermp:no-trigger-op

Conversation

@cartermp

@cartermp cartermp commented Dec 4, 2017

Copy link
Copy Markdown
Contributor

I noticed this when I mistyped |. the other day. I threw this together quickly and must now leave for the office on the ferry, so I likely won't be able to address feedback until tomorrow. I installed it into my VS and things seemed to work.

@cartermp cartermp changed the title No triggered completion on operators Do not trigger completion on operators Dec 4, 2017
let! sourceText = context.Document.GetTextAsync(context.CancellationToken)
let defines = projectInfoManager.GetCompilationDefinesForEditingDocument(document)
do! Option.guard (CompletionUtils.shouldProvideCompletion(document.Id, document.FilePath, defines, sourceText, context.Position))
//let defines = projectInfoManager.GetCompilationDefinesForEditingDocument(document)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Derp, I need to just delete this line; provided my change to calling ShouldTriggerCompletion be the right thing

module internal CompletionUtils =

let private isPotentialOperatorChar (ch: char) =
match ch with

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be more characters to use here; I'll look at it again

&&
(triggerChar = '.' || (Settings.IntelliSense.ShowAfterCharIsTyped && isStartingNewWord(sourceText, triggerPosition)))
&&
not (isPotentialOperatorChar prevChar) No newline at end of file

@saul saul Dec 5, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to break completion in these contexts:

[<|Attribute // within attribute
&|foo // byref of variable foo
1.0/| // after division

etc?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did, and I now realized that this whole original idea is just silly. The classification data can tell if we're in the middle of an operator already.

@cartermp
cartermp requested a review from TIHan December 6, 2017 17:49
| ClassificationTypeNames.Comment
| ClassificationTypeNames.StringLiteral
| ClassificationTypeNames.ExcludedCode
| ClassificationTypeNames.Operator

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is what fixes the issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be all you need.

let! sourceText = context.Document.GetTextAsync(context.CancellationToken)
let defines = projectInfoManager.GetCompilationDefinesForEditingDocument(document)
do! Option.guard (CompletionUtils.shouldProvideCompletion(document.Id, document.FilePath, defines, sourceText, context.Position))
do! Option.guard (this.ShouldTriggerCompletion(sourceText, context.Position, context.Trigger, null))

@TIHan TIHan Dec 6, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ShouldTriggerCompletion will fire once you type a character; however, you can ctrl+space to bring up completions and this will not fire ShouldTriggerCompletion. Instead, it will go right to ProvideCompletionsAsync.

ProvideCompletionsAsync should not be checking for a dot to get completions. That's the responsibility of ShouldTriggerCompletion.

I recommend making this go back to what it was.

)) No newline at end of file
))
&&
(triggerChar = '.' || (Settings.IntelliSense.ShowAfterCharIsTyped && isStartingNewWord(sourceText, triggerPosition))) No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the logic of putting this here. But, considering the comment I made on ShouldTriggerCompletion and ProvideCompletionsAsync, this bit that's checking does not belong in the flow of ProvideCompletionsAsync. I recommend putting this back to the way it was.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. Hmmm. This logic is really just strewn about. I'd like to clean it up in this PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to clean things up, just create some more functions that contain these kind of checks. :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll just do that separately. I'm thinking of a winter project of porting the old completion tests over to CompletionProvider so I might as well try to clean a few things up at this time too

@TIHan TIHan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the current changes, consider this code:

let f x y = x + y

let x = 1

f ^

With the cursor right at f. If I ctrl+space, I get nothing. This is due to ProvideCompletionsAsync checking for the dot.

@TIHan

TIHan commented Dec 6, 2017

Copy link
Copy Markdown
Contributor

Considering the problem mentioned in the review, I am very surprised the tests passed. Perhaps we should provide a test for that case.

@vasily-kirichenko

Copy link
Copy Markdown
Contributor

@TIHan BTW, there are no tests for ShouldTriggerCompletion at all (because it was triggered by dot only in pre-2017 era).

@TIHan

TIHan commented Dec 6, 2017

Copy link
Copy Markdown
Contributor

@vasily-kirichenko I made an issue regarding that then: #4069

Will be good to have tests against it. :)

@TIHan

TIHan commented Dec 6, 2017

Copy link
Copy Markdown
Contributor

@dotnet-bot test Ubuntu14.04 Release_fcs Build please

@TIHan
TIHan merged commit 94c7fe1 into dotnet:master Dec 6, 2017
@cartermp
cartermp deleted the no-trigger-op branch December 6, 2017 23:33
KevinRansom pushed a commit that referenced this pull request Dec 7, 2017
* do not simplify open statements (#4068)

* 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
KevinRansom pushed a commit that referenced this pull request Dec 8, 2017
* do not simplify open statements (#4068)

* 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
@dsyme

dsyme commented Dec 12, 2017

Copy link
Copy Markdown
Contributor

I'm catching up old notifications - but just to say "great job!" on this :)

nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Jan 26, 2022
* No triggered completion on operators

* Check with classification data instead of stupid custom stuff

* Fix silly tests

* Feedback
nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Jan 26, 2022
* do not simplify open statements (dotnet#4068)

* Do not trigger completion on operators (dotnet#4054)

* No triggered completion on operators

* Check with classification data instead of stupid custom stuff

* Fix silly tests

* Feedback
T-Gro pushed a commit that referenced this pull request Jun 12, 2026
* No triggered completion on operators

* Check with classification data instead of stupid custom stuff

* Fix silly tests

* Feedback
T-Gro pushed a commit that referenced this pull request Jun 12, 2026
* do not simplify open statements (#4068)

* 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
T-Gro pushed a commit that referenced this pull request Jun 12, 2026
* do not simplify open statements (#4068)

* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants