Skip to content

Commit 8642b10

Browse files
committed
commit uncommited
1 parent 3a4837c commit 8642b10

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"javascript",
2323
"plugin",
2424
"webstorm",
25-
"TypeScript Hero"
25+
"typescript hero"
2626
],
2727
"activationEvents": [
2828
"onLanguage:javascript",

typescript/src/completionsAtPosition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export const getCompletionsAtPosition = (
228228

229229
// prevent vscode-builtin wrong insertText with methods snippets enabled
230230
if (!isGoodPositionBuiltinMethodCompletion(ts, sourceFile, position)) {
231-
prior.entries = prior.entries.map(item => ({ ...item, insertText: item.insertText ?? item.name, isSnippet: true }))
231+
prior.entries = prior.entries.map(item => ({ ...item, insertText: (item.insertText ?? item.name).replace(/\$/g, '\\$'), isSnippet: true }))
232232
}
233233

234234
if (c('correctSorting.enable')) prior.entries = prior.entries.map((entry, index) => ({ ...entry, sortText: `${entry.sortText ?? ''}${index}` }))

typescript/src/dummyLanguageService.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ export const createLanguageService = (files: Record<string, string>) => {
1515
},
1616
getCurrentDirectory: () => '',
1717
getDefaultLibFileName: () => require.resolve('typescript/lib/lib.esnext.full.d.ts'),
18+
fileExists(path) {
19+
return path in files
20+
},
21+
readFile(path) {
22+
return files[path]!
23+
},
1824
})
1925
return {
2026
languageService,

typescript/src/isGoodPositionMethodCompletion.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ import type tslib from 'typescript/lib/tsserverlibrary'
22
import { findChildContainingPosition, findChildContainingPositionMaxDepth } from './utils'
33

44
export const isGoodPositionBuiltinMethodCompletion = (ts: typeof tslib, sourceFile: tslib.SourceFile, position: number) => {
5-
const importClauseCandidate = findChildContainingPositionMaxDepth(ts, sourceFile, position, 2)
6-
console.log(sourceFile.getFullText().slice(0, position))
7-
if (importClauseCandidate?.kind === 266) return false
8-
const currentNode = findChildContainingPosition(ts, sourceFile, position)
9-
// const obj = { method() {}, arrow: () => {} }
10-
// type A = typeof obj["|"]
11-
if (currentNode && ts.isStringLiteralLike(currentNode)) return false
5+
const importClauseCandidate = findChildContainingPositionMaxDepth(ts, sourceFile, position, 3)
6+
if (importClauseCandidate && ts.isImportClause(importClauseCandidate)) return false
7+
let currentNode = findChildContainingPosition(ts, sourceFile, position)
8+
if (currentNode) {
9+
// const obj = { method() {}, arrow: () => {} }
10+
// type A = typeof obj["|"]
11+
if (ts.isStringLiteralLike(currentNode)) return false
12+
if (ts.isIdentifier(currentNode)) currentNode = currentNode.parent
13+
if (ts.isShorthandPropertyAssignment(currentNode)) currentNode = currentNode.parent
14+
if (ts.isObjectBindingPattern(currentNode) || ts.isObjectLiteralExpression(currentNode)) return false
15+
}
1216
return true
1317
}
1418

0 commit comments

Comments
 (0)