Skip to content

Commit 9941886

Browse files
authored
Merge pull request #134 from zardoy/develop
2 parents a98aaae + 55f4aac commit 9941886

File tree

6 files changed

+31
-11
lines changed

6 files changed

+31
-11
lines changed

typescript/src/completions/isGoodPositionMethodCompletion.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ export const isGoodPositionMethodCompletion = (sourceFile: ts.SourceFile, positi
1111
// type A = typeof obj["|"]
1212
if (ts.isStringLiteralLike(currentNode)) return false
1313
if (ts.isNamedExports(currentNode)) return false
14+
if (
15+
ts.isIdentifier(currentNode) &&
16+
ts.isBinaryExpression(currentNode.parent) &&
17+
currentNode.parent.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
18+
currentNode === currentNode.parent.left
19+
) {
20+
return false
21+
}
1422
if (ts.isIdentifier(currentNode)) currentNode = currentNode.parent
1523
if (ts.isExportSpecifier(currentNode)) return false
1624
if (ts.isJsxSelfClosingElement(currentNode) || ts.isJsxOpeningElement(currentNode)) return false

typescript/src/completionsAtPosition.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ export const getCompletionsAtPosition = (
223223
// )
224224
const indexToPatch = prior.entries.findIndex(({ name, kind }) => name === 'toString' && kind !== ts.ScriptElementKind.warning)
225225
if (indexToPatch !== -1) {
226-
prior.entries[indexToPatch]!.insertText = `${prior.entries[indexToPatch]!.insertText ?? prior.entries[indexToPatch]!.name}()`
227-
prior.entries[indexToPatch]!.kind = ts.ScriptElementKind.constElement
228-
// prior.entries[indexToPatch]!.isSnippet = true
226+
const entryToPatch = prior.entries[indexToPatch]!
227+
entryToPatch.insertText = `${entryToPatch.insertText ?? entryToPatch.name}()`
228+
entryToPatch.isSnippet = true
229+
entryToPatch.kind = ts.ScriptElementKind.constElement
229230
}
230231
}
231232

typescript/src/definitions.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,20 @@ export default (proxy: ts.LanguageService, languageService: ts.LanguageService,
164164
const lines = sourceFile.getFullText().split('\n')
165165
const { line: curLine } = ts.getLineAndCharacterOfPosition(sourceFile, position)
166166

167-
const VLS_COMPONENT_STRING = `__VLS_templateComponents`
168-
const isTemplateComponent = lines[curLine]?.startsWith(VLS_COMPONENT_STRING)
169-
if (!isTemplateComponent) return
167+
const VLS_COMPONENT_STRINGS = ['__VLS_templateComponents', '__VLS_components']
170168

169+
const isVLSComponent = VLS_COMPONENT_STRINGS.some(VLS_COMPONENT_STRING => lines[curLine]?.startsWith(VLS_COMPONENT_STRING))
171170
const componentName = lines[curLine]?.match(/\.(\w+);?/)?.[1]
172-
if (!componentName) return
173171

174-
prior.definitions = prior.definitions.filter(({ name }) => !(componentName === name && lines[curLine - 2] === '// @ts-ignore'))
172+
prior.definitions =
173+
!isVLSComponent || !componentName
174+
? prior.definitions
175+
: prior.definitions.filter(({ name, containerName }) => {
176+
const isDefinitionInComponentsProperty = componentName === name && lines[curLine - 2] === '// @ts-ignore'
177+
const isGlobalComponent = containerName === 'GlobalComponents'
178+
179+
return !isDefinitionInComponentsProperty || isGlobalComponent
180+
})
175181
}
176182

177183
return prior

typescript/src/getPatchedNavTree.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const getPatchedNavModule = (additionalFeatures: AdditionalFeatures): { getNavig
2828
// transform?: (found: string, content: string, position: number) => [string?, string?]
2929
}
3030
const addChildrenRecursivelySwitchFirstCase = ['function addChildrenRecursively(node)', 'switch (node.kind)']
31+
const typeAliasCaseNeedle = [...addChildrenRecursivelySwitchFirstCase, 'TypeAliasDeclaration */']
3132

3233
const patchLocations: PatchLocation[] = [
3334
{
@@ -44,7 +45,7 @@ const getPatchedNavModule = (additionalFeatures: AdditionalFeatures): { getNavig
4445
break;`,
4546
},
4647
{
47-
searchString: 'case 262 /* SyntaxKind.TypeAliasDeclaration */',
48+
searchString: typeAliasCaseNeedle,
4849
linesOffset: 3,
4950
// https://github.com/microsoft/TypeScript/pull/52558/
5051
addString: /* js */ `
@@ -54,7 +55,7 @@ const getPatchedNavModule = (additionalFeatures: AdditionalFeatures): { getNavig
5455
`,
5556
},
5657
{
57-
searchString: 'case 262 /* SyntaxKind.TypeAliasDeclaration */',
58+
searchString: typeAliasCaseNeedle,
5859
linesOffset: 0,
5960
removeLines: 1,
6061
},

typescript/src/volarConfig.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ const plugin = ((context, { typescript: tsModule } = {}) => {
5050

5151
const getResolvedUserConfig = async () => {
5252
const regularConfig = await configurationHost.getConfiguration!<any>('tsEssentialPlugins')
53-
const _vueSpecificConfig = await configurationHost.getConfiguration!<any>('[vue]')
53+
const _vueSpecificConfig = (await configurationHost.getConfiguration!<any>('[vue]')) || {}
54+
5455
const vueSpecificConfig = Object.fromEntries(
5556
compact(
5657
Object.entries(_vueSpecificConfig).map(([key, value]) =>

typescript/test/completions.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ test('Banned positions for all method snippets', () => {
5656
test({
5757
/*|*/
5858
})
59+
test/*|*/ = test
5960
;<Test/*|*/ />
6061
;<Test/*|*/></Test>
6162
;<Test test={/*|*/}></Test>
@@ -83,6 +84,8 @@ test('Not banned positions for method snippets', () => {
8384
method: setTimeout/*|*/
8485
})
8586
test2/*|*/
87+
test = test/*|*/
88+
test/*|*/ >= test/*|*/
8689
`)
8790
for (const [i, pos] of cursorPositions.entries()) {
8891
const result = isGoodPositionMethodCompletion(getSourceFile(), pos - 1, defaultConfigFunc)

0 commit comments

Comments
 (0)