Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/language-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ export class CompletionsProviderImpl implements CompletionsProvider<CompletionEn
comp.name,
{},
comp.source,
userPreferences
userPreferences,
comp.data
);

if (detail) {
Expand Down Expand Up @@ -390,11 +391,11 @@ export class CompletionsProviderImpl implements CompletionsProvider<CompletionEn
}

private getCompletionDocument(compDetail: ts.CompletionEntryDetails) {
const { source, documentation: tsDocumentation, displayParts, tags } = compDetail;
const { sourceDisplay, documentation: tsDocumentation, displayParts, tags } = compDetail;
let detail: string = this.changeSvelteComponentName(ts.displayPartsToString(displayParts));

if (source) {
const importPath = ts.displayPartsToString(source);
if (sourceDisplay) {
const importPath = ts.displayPartsToString(sourceDisplay);
detail = `Auto import from ${importPath}\n${detail}`;
}

Expand Down
10 changes: 5 additions & 5 deletions packages/language-server/src/plugins/typescript/previewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ function getTagBodyText(tag: ts.JSDocTagInfo): string | undefined {

switch (tag.name) {
case 'example':
return makeExampleTag(tag.text);
return makeExampleTag(ts.displayPartsToString(tag.text));
case 'author':
return makeEmailTag(tag.text);
return makeEmailTag(ts.displayPartsToString(tag.text));
case 'default':
return makeCodeblock(tag.text);
return makeCodeblock(ts.displayPartsToString(tag.text));
}

return processInlineTags(tag.text);
return processInlineTags(ts.displayPartsToString(tag.text));
}

export function getTagDocumentation(tag: ts.JSDocTagInfo): string | undefined {
function getWithType() {
const body = (tag.text || '').split(/^(\S+)\s*-?\s*/);
const body = (ts.displayPartsToString(tag.text) || '').split(/^(\S+)\s*-?\s*/);
if (body?.length === 3) {
const param = body[1];
const doc = body[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,13 @@ describe('CompletionProviderImpl', () => {
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',
Expand All @@ -283,6 +286,7 @@ describe('CompletionProviderImpl', () => {
replacementSpan: undefined,
sortText: '1',
source: undefined,
sourceDisplay: undefined,
uri: fileNameToAbsoluteUri(filename)
} as CompletionEntryWithIdentifer);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
Expand All @@ -36,17 +38,17 @@ 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,
Expand All @@ -55,11 +57,39 @@ 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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script>
console.log();
</script>
2 changes: 1 addition & 1 deletion packages/svelte-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte2tsx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down