Don't include completions for current and later parameters#52690
Don't include completions for current and later parameters#52690DanielRosenwasser merged 19 commits intomicrosoft:mainfrom
Conversation
DanielRosenwasser
left a comment
There was a problem hiding this comment.
The test file should be renamed:
tests/cases/fourslash/noIncorrectParamaterCompletions.ts
tests/cases/fourslash/noCompletionsForCurrentOrLaterParameters.ts
src/services/completions.ts
Outdated
| const variableDeclaration = getVariableDeclaration(location); | ||
| const parameterDeclaration = getParameterDeclaration(contextToken); |
There was a problem hiding this comment.
Can you just switch the helper function to just be getVariableOrParameterDeclaration and make decisions based on that?
There was a problem hiding this comment.
So your decision is to unify variableDeclaration and parameterDeclaration?
eg
const variableOrParameterDeclaration = getVariableOrParameterDeclaration(location, contextToken)But what about this case then?:
const foo = (a = foo/*no foo suggestion*/) => {
console.log(foo)
}There was a problem hiding this comment.
BTW its fully valid location for foo suggestion, so maybe you're right
There was a problem hiding this comment.
I switched to getVariableOrParameterDeclaration(contextToken: Node | undefined). I'm using only contextToken to fit logic in single findAncestor. I don't really the idea of dropping location as I feel it can introduce a lot of breakage, though I'll look at tests and try to fix them
There was a problem hiding this comment.
BTW its fully valid location for foo suggestion, so maybe you're right
FYI
src/services/completions.ts
Outdated
| // Filter out parameters from their own initializers | ||
| // `function f(a = /* no 'a' here */) { }` | ||
| if (symbol.valueDeclaration === parameterDeclaration) { | ||
| return false; | ||
| } | ||
| // Filter out parameters from other parameters' initializers | ||
| // `function f(a = /* no 'b' here */, b) { }` | ||
| const parameters = parameterDeclaration.parent.parameters; | ||
| const currentParamIdx = parameters.indexOf(parameterDeclaration); | ||
| if (parameters.slice(currentParamIdx).some((p) => symbol.valueDeclaration === p)) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
I wonder if you could just get await with using the node positions.
| // Filter out parameters from their own initializers | |
| // `function f(a = /* no 'a' here */) { }` | |
| if (symbol.valueDeclaration === parameterDeclaration) { | |
| return false; | |
| } | |
| // Filter out parameters from other parameters' initializers | |
| // `function f(a = /* no 'b' here */, b) { }` | |
| const parameters = parameterDeclaration.parent.parameters; | |
| const currentParamIdx = parameters.indexOf(parameterDeclaration); | |
| if (parameters.slice(currentParamIdx).some((p) => symbol.valueDeclaration === p)) { | |
| return false; | |
| } | |
| const declarationPos = symbol.valueDeclaration.pos; | |
| if (parameterDeclaration.pos <= declarationPos && declarationPos < parameters.end) { | |
| return false; | |
| } |
There was a problem hiding this comment.
Seems to be good idea! but I still wonder why do we need declarationPos < parameters.end check?
|
Didn't expect so many failing tests 😅 , will look again at them in a few days |
though it was enough to do most top contextToken only, but lets be consistent in code
|
It seems using contextToken in new implementation improved quality in some test cases, I'm happy with result |
|
Also I have a quick question. Speaking of let fileName
const foo = (displayName = fileNam/*<-*/, fileName2) => {
// ERROR: Cannot find name 'fileNam'. Did you mean 'fileName2'?
// super annoying sometimes, would be cool if codefixes were smarter
} |
|
@DanielRosenwasser I'm sorry to bother you, but I wanted to do the same for type parameters. Would it be better to do it in this PR or create another one after its get merged? Its just a matter of adding an extra check 😉. |
How simple are we talking? If it's not too bad, I don't think it's a big deal to include it here. |
pick changes from 3f2a0ff
Okay, I think it's done |
sandersn
left a comment
There was a problem hiding this comment.
Very nice and small change. I had some questions and suggestions.
|
I see it's in waiting on author. Is anything else required here from my side? |
|
I was waiting on a review from @DanielRosenwasser since he previously requested changes. |
Tried to find oldest completion issue :)
Fixes #1858