From 2a6ee3bb873876d00c51a1c14dc38d743971b9c9 Mon Sep 17 00:00:00 2001 From: Lyu Jason Date: Thu, 27 May 2021 12:01:07 +0800 Subject: [PATCH 1/3] bumps typescript to 4.3 --- package.json | 2 +- packages/language-server/README.md | 2 +- .../plugins/typescript/features/CompletionProvider.ts | 9 +++++---- .../src/plugins/typescript/previewer.ts | 10 +++++----- .../typescript/features/CompletionProvider.test.ts | 4 ++++ packages/svelte-vscode/package.json | 2 +- packages/svelte2tsx/package.json | 2 +- yarn.lock | 8 ++++---- 8 files changed, 22 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 0468be668..063db7658 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "lint": "prettier --check . && eslint \"packages/**/*.{ts,js}\"" }, "dependencies": { - "typescript": "^4.2.2" + "typescript": "^4.3.2" }, "devDependencies": { "@sveltejs/eslint-config": "github:sveltejs/eslint-config#v5.2.0", diff --git a/packages/language-server/README.md b/packages/language-server/README.md index b851da0fc..585c531db 100644 --- a/packages/language-server/README.md +++ b/packages/language-server/README.md @@ -145,7 +145,7 @@ Enable signature help (parameter hints) for JS/TS. _Default_: `true` ##### `svelte.plugin.typescript.semanticTokens.enable` -Enable semantic tokens (semantic highlight) for TypeScript. Doesn't apply to JavaScript. _Default_: `true` +Enable semantic tokens (semantic highlight) for TypeScript. _Default_: `true` ##### `svelte.plugin.css.enable` diff --git a/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts b/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts index c77119c08..ecbcd2a03 100644 --- a/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts +++ b/packages/language-server/src/plugins/typescript/features/CompletionProvider.ts @@ -352,7 +352,8 @@ export class CompletionsProviderImpl implements CompletionsProvider { const { data } = completions!.items[0]; assert.deepStrictEqual(data, { + data: undefined, hasAction: undefined, insertText: undefined, isPackageJsonImport: undefined, + isImportStatementCompletion: undefined, isRecommended: undefined, + isSnippet: undefined, kind: 'method', kindModifiers: '', name: 'b', @@ -283,6 +286,7 @@ describe('CompletionProviderImpl', () => { replacementSpan: undefined, sortText: '1', source: undefined, + sourceDisplay: undefined, uri: fileNameToAbsoluteUri(filename) } as CompletionEntryWithIdentifer); }); diff --git a/packages/svelte-vscode/package.json b/packages/svelte-vscode/package.json index 632937cf7..a6cb790df 100644 --- a/packages/svelte-vscode/package.json +++ b/packages/svelte-vscode/package.json @@ -158,7 +158,7 @@ "type": "boolean", "default": true, "title": "TypeScript: Semantic Tokens", - "description": "Enable semantic tokens (semantic highlight) for TypeScript. Doesn't apply to JavaScript" + "description": "Enable semantic tokens (semantic highlight) for TypeScript." }, "svelte.plugin.css.enable": { "type": "boolean", diff --git a/packages/svelte2tsx/package.json b/packages/svelte2tsx/package.json index 639991891..fcec0cce3 100644 --- a/packages/svelte2tsx/package.json +++ b/packages/svelte2tsx/package.json @@ -37,7 +37,7 @@ "svelte": "~3.38.2", "tiny-glob": "^0.2.6", "tslib": "^1.10.0", - "typescript": "^4.2.2" + "typescript": "^4.3.2" }, "peerDependencies": { "svelte": "^3.24", diff --git a/yarn.lock b/yarn.lock index 413bdad63..0bba70785 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2556,10 +2556,10 @@ type-fest@^0.8.1: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d" integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA== -typescript@*, typescript@^4.2.2: - version "4.2.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.2.tgz#1450f020618f872db0ea17317d16d8da8ddb8c4c" - integrity sha512-tbb+NVrLfnsJy3M59lsDgrzWIflR4d4TIUjz+heUnHZwdF7YsrMTKoRERiIvI2lvBG95dfpLxB21WZhys1bgaQ== +typescript@*, typescript@^4.3.2: + version "4.3.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.2.tgz#399ab18aac45802d6f2498de5054fcbbe716a805" + integrity sha512-zZ4hShnmnoVnAHpVHWpTcxdv7dWP60S2FsydQLV8V5PbS3FifjWFFRiHSWpDJahly88PRyV5teTSLoq4eG7mKw== unist-util-stringify-position@^2.0.0: version "2.0.3" From 60033a487c65430f8391a68f4fb9d7827da50e93 Mon Sep 17 00:00:00 2001 From: Lyu Jason Date: Thu, 27 May 2021 16:13:10 +0800 Subject: [PATCH 2/3] test for js semantic tokens --- .../features/SemanticTokensProvider.test.ts | 92 +++++++++++++------ .../testfiles/semantic-tokens/jsToken.svelte | 3 + 2 files changed, 67 insertions(+), 28 deletions(-) create mode 100644 packages/language-server/test/plugins/typescript/testfiles/semantic-tokens/jsToken.svelte diff --git a/packages/language-server/test/plugins/typescript/features/SemanticTokensProvider.test.ts b/packages/language-server/test/plugins/typescript/features/SemanticTokensProvider.test.ts index 605a03f6e..2616471ca 100644 --- a/packages/language-server/test/plugins/typescript/features/SemanticTokensProvider.test.ts +++ b/packages/language-server/test/plugins/typescript/features/SemanticTokensProvider.test.ts @@ -17,11 +17,13 @@ import { pathToUrl } from '../../../../src/utils'; const testDir = path.join(__dirname, '..'); describe('SemanticTokensProvider', () => { - function setup() { + const tsFile = 'tokens.svelte'; + + function setup(filename: string) { const docManager = new DocumentManager( (textDocument) => new Document(textDocument.uri, textDocument.text) ); - const filePath = path.join(testDir, 'testfiles', 'semantic-tokens', 'tokens.svelte'); + const filePath = path.join(testDir, 'testfiles', 'semantic-tokens', filename); const lsAndTsDocResolver = new LSAndTSDocResolver( docManager, [pathToUrl(testDir)], @@ -36,17 +38,18 @@ describe('SemanticTokensProvider', () => { } it('provides semantic token', async () => { - const { provider, document } = setup(); + const { provider, document } = setup(tsFile); const { data } = (await provider.getSemanticTokens(document)) ?? { data: [] }; - assertResult(data, getExpected(/* isFull */ true)); + assertResult(data, getTsExpected(/* isFull */ true)); }); + it('provides partial semantic token', async () => { - const { provider, document } = setup(); + const { provider, document } = setup(tsFile); const { data } = (await provider.getSemanticTokens( document, @@ -55,11 +58,38 @@ describe('SemanticTokensProvider', () => { data: [] }; - assertResult(data, getExpected(/* isFull */ false)); + assertResult(data, getTsExpected(/* isFull */ false)); + }); + + it('provides semantic token for js', async () => { + const { provider, document } = setup('jsToken.svelte'); + + const { data } = (await provider.getSemanticTokens( + document + )) ?? { + data: [] + }; + + assertResult(data, buildExpected([ + { + character: 4, + line: 1, + length: 'console'.length, + modifiers: [TokenModifier.defaultLibrary], + type: TokenType.variable + }, + { + character: 12, + line: 1, + length: 'log'.length, + modifiers: [TokenModifier.defaultLibrary], + type: TokenType.member + } + ])); }); it('can cancel semantic token before promise resolved', async () => { - const { provider, document } = setup(); + const { provider, document } = setup(tsFile); const cancellationTokenSource = new CancellationTokenSource(); const tokenPromise = provider.getSemanticTokens( document, @@ -71,14 +101,32 @@ describe('SemanticTokensProvider', () => { assert.deepStrictEqual(await tokenPromise, null); }); - function getExpected(full: boolean) { - const tokenDataScript: Array<{ - line: number; - character: number; - length: number; - type: number; - modifiers: number[]; - }> = [ + interface TokenData { + line: number; + character: number; + length: number; + type: number; + modifiers: number[]; + } + + function buildExpected(tokenData: TokenData[]) { + const builder = new SemanticTokensBuilder(); + for (const token of tokenData) { + builder.push( + token.line, + token.character, + token.length, + token.type, + token.modifiers.reduce((pre, next) => pre | (1 << next), 0) + ); + } + + const data = builder.build().data; + return data; + } + + function getTsExpected(full: boolean) { + const tokenDataScript: TokenData[] = [ { line: 2, character: 14, @@ -175,19 +223,7 @@ describe('SemanticTokensProvider', () => { } ]; - const builder = new SemanticTokensBuilder(); - for (const token of full ? tokenDataAll : tokenDataScript) { - builder.push( - token.line, - token.character, - token.length, - token.type, - token.modifiers.reduce((pre, next) => pre | (1 << next), 0) - ); - } - - const data = builder.build().data; - return data; + return buildExpected(full ? tokenDataAll : tokenDataScript); } /** diff --git a/packages/language-server/test/plugins/typescript/testfiles/semantic-tokens/jsToken.svelte b/packages/language-server/test/plugins/typescript/testfiles/semantic-tokens/jsToken.svelte new file mode 100644 index 000000000..99bd26eaf --- /dev/null +++ b/packages/language-server/test/plugins/typescript/testfiles/semantic-tokens/jsToken.svelte @@ -0,0 +1,3 @@ + From c5ac9d5d810d642b6d748894937f8299be2dc66a Mon Sep 17 00:00:00 2001 From: Lyu Jason Date: Thu, 27 May 2021 16:16:05 +0800 Subject: [PATCH 3/3] lint --- .../features/SemanticTokensProvider.test.ts | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/language-server/test/plugins/typescript/features/SemanticTokensProvider.test.ts b/packages/language-server/test/plugins/typescript/features/SemanticTokensProvider.test.ts index 2616471ca..67c04996c 100644 --- a/packages/language-server/test/plugins/typescript/features/SemanticTokensProvider.test.ts +++ b/packages/language-server/test/plugins/typescript/features/SemanticTokensProvider.test.ts @@ -47,7 +47,6 @@ describe('SemanticTokensProvider', () => { assertResult(data, getTsExpected(/* isFull */ true)); }); - it('provides partial semantic token', async () => { const { provider, document } = setup(tsFile); @@ -64,28 +63,29 @@ describe('SemanticTokensProvider', () => { it('provides semantic token for js', async () => { const { provider, document } = setup('jsToken.svelte'); - const { data } = (await provider.getSemanticTokens( - document - )) ?? { + const { data } = (await provider.getSemanticTokens(document)) ?? { data: [] }; - assertResult(data, buildExpected([ - { - character: 4, - line: 1, - length: 'console'.length, - modifiers: [TokenModifier.defaultLibrary], - type: TokenType.variable - }, - { - character: 12, - line: 1, - length: 'log'.length, - modifiers: [TokenModifier.defaultLibrary], - type: TokenType.member - } - ])); + assertResult( + data, + buildExpected([ + { + character: 4, + line: 1, + length: 'console'.length, + modifiers: [TokenModifier.defaultLibrary], + type: TokenType.variable + }, + { + character: 12, + line: 1, + length: 'log'.length, + modifiers: [TokenModifier.defaultLibrary], + type: TokenType.member + } + ]) + ); }); it('can cancel semantic token before promise resolved', async () => {