Skip to content

Commit 1d439f2

Browse files
committed
fix: remove workaround to place previous variable completion at top, update TS (now there is a command for this) or/and enable locality bonus!
1 parent cc49905 commit 1d439f2

File tree

1 file changed

+3
-31
lines changed

1 file changed

+3
-31
lines changed

typescript/src/completions/boostNameSuggestions.ts

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { getCannotFindCodes } from '../utils/cannotFindCodes'
33

44
const cannotFindCodes = getCannotFindCodes({ includeFromLib: true })
55

6-
// 1. add suggestions for unresolved indentifiers in code
7-
// 2. boost identifer or type name suggestion
6+
// 1. add suggestions for unresolved identifiers in code
7+
// 2. boost identifier or type name suggestion
88
export default (
99
entries: ts.CompletionEntry[],
1010
position: number,
@@ -17,35 +17,7 @@ export default (
1717
const fileText = sourceFile.getFullText()
1818
const fileTextBeforePos = fileText.slice(0, position)
1919
const beforeConstNodeOffset = fileTextBeforePos.match(/(?:const|let) ([\w\d]*)$/i)?.[1]
20-
const nodeWithStatements = node => {
21-
return node && 'statements' in node && Array.isArray(node.statements) ? node : undefined
22-
}
23-
const statementsNode = nodeWithStatements(node) || nodeWithStatements(node.parent)
24-
// Workaround for current locality bonus & TS 5.1
25-
if (
26-
statementsNode &&
27-
// ensure completions are not blocked
28-
entries.length > 0
29-
) {
30-
const statements = statementsNode.statements as any[]
31-
const prevNode =
32-
statementsNode === node
33-
? [...statements].reverse().find((statement: ts.Node) => statement.pos + statement.getLeadingTriviaWidth() < position)
34-
: statements[statements.indexOf(node) - 1]
35-
if (prevNode && ts.isVariableStatement(prevNode) && prevNode.declarationList.declarations.length === 1) {
36-
const { name } = prevNode.declarationList.declarations[0]!
37-
if (ts.isIdentifier(name)) {
38-
const kind: ts.ScriptElementKind =
39-
prevNode.declarationList.flags & ts.NodeFlags.Const ? ts.ScriptElementKind.constElement : ts.ScriptElementKind.letElement
40-
entries = boostOrAddSuggestions(entries, [
41-
{
42-
name: name.text,
43-
kind,
44-
},
45-
])
46-
}
47-
}
48-
}
20+
4921
/** false - pick all identifiers after cursor
5022
* node - pick identifiers that within node */
5123
let filterBlock: undefined | false | ts.Node

0 commit comments

Comments
 (0)