-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: include fix for builtin `typescript.suggest.completeFunctionCal…
…ls` in some positions out of the box fix: don't insert method snippet in some positions, inclusing const assigning
- Loading branch information
Showing
4 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type tslib from 'typescript/lib/tsserverlibrary' | ||
import { findChildContainingPosition } from './utils' | ||
|
||
export const isGoodPositionBuiltinMethodCompletion = (ts: typeof tslib, sourceFile: tslib.SourceFile, position: number) => { | ||
const importClauseCandidate = findChildContainingPosition(ts, sourceFile, position, 2) | ||
if (importClauseCandidate?.kind === 266) return false | ||
const currentNode = findChildContainingPosition(ts, sourceFile, position) | ||
// const obj = { method() {}, arrow: () => {} } | ||
// type A = typeof obj["|"] | ||
if (currentNode && ts.isStringLiteralLike(currentNode)) return false | ||
return true | ||
} | ||
|
||
export const isGoodPositionMethodCompletion = ( | ||
ts: typeof tslib, | ||
fileName: string, | ||
sourceFile: tslib.SourceFile, | ||
position: number, | ||
languageService: tslib.LanguageService, | ||
) => { | ||
if (!isGoodPositionBuiltinMethodCompletion(ts, sourceFile, position)) return false | ||
const { kind } = languageService.getQuickInfoAtPosition(fileName, position) ?? {} | ||
switch (kind) { | ||
case 'var': | ||
case 'let': | ||
case 'const': | ||
case 'alias': | ||
return false | ||
} | ||
// TODO check for brace here | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters