Skip to content

Commit 641b781

Browse files
committed
Merge branch 'master' of https://github.com/sveltejs/language-tools into js-doc-support
2 parents e1ba27c + cb5f91d commit 641b781

File tree

17 files changed

+139
-193
lines changed

17 files changed

+139
-193
lines changed

.github/workflows/Deploy.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Weekly builds of the Svelte Language Tools Beta
2+
3+
# For testing
4+
# on: push
5+
6+
# For production
7+
on:
8+
schedule:
9+
- cron: "0 4 * * *"
10+
11+
jobs:
12+
deploy:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: actions/setup-node@v1
18+
with:
19+
node-version: "10.x"
20+
registry-url: "https://registry.npmjs.org"
21+
22+
# Ensure everything is compiling
23+
- run: "yarn install"
24+
- run: "yarn build"
25+
26+
# Lets us use one-liner JSON manipulations the package.json files
27+
- run: "npm install -g json"
28+
29+
# Setup the environment
30+
- run: 'json -I -f packages/svelte-vscode/package.json -e "this.dependencies[\`svelte-language-server\`]=\`file:../language-server\`"'
31+
- run: 'json -I -f packages/svelte-vscode/package.json -e "this.version=\`99.0.0\`"'
32+
33+
# To deploy we need a node_modules folder which isn't in the yarn
34+
# So, remove the workspace
35+
- run: "rm package.json yarn.lock"
36+
37+
# Re-run the yarn install outside of the workspaceSetup the language server
38+
- run: |
39+
cd packages/language-server
40+
yarn install
41+
cd ..
42+
43+
# Re-run the yarn install outside of the workspace
44+
- run: |
45+
cd packages/svelte-vscode
46+
yarn install
47+
48+
# Just a hard constraint from azure
49+
echo "Once a year this expires, tell Orta to access https://dev.azure.com/ortatherox0608/_usersSettings/tokens to get a new one"
50+
51+
npx vsce publish patch --yarn -p $VSCE_TOKEN
52+
53+
env:
54+
VSCE_TOKEN: ${{ secrets.AZURE_PAN_TOKEN }}
55+

packages/language-server/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,4 @@ Currently Supported:
4646

4747
Install a plugin for your editor:
4848

49-
- [VS Code](https://github.com/UnwrittenFun/svelte-vscode)
50-
- [Atom](https://github.com/UnwrittenFun/svelte-atom)
51-
- [(Neo)vim](https://github.com/coc-extensions/coc-svelte)
49+
- [VS Code](../svelte-vscode)

packages/language-server/src/lib/PluginHost.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,20 @@ export class PluginHost {
4646
switch (mode) {
4747
case ExecuteMode.FirstNonNull:
4848
for (const plugin of plugins) {
49-
const res = await plugin[name](...args);
49+
const res = await this.tryExecutePlugin(plugin, name, args, null);
5050
if (res != null) {
5151
return res;
5252
}
5353
}
5454
return null;
5555
case ExecuteMode.Collect:
56-
return Promise.all(plugins.map(plugin => plugin[name](...args)));
56+
return Promise.all(
57+
plugins.map(plugin => this.tryExecutePlugin(plugin, name, args, [])),
58+
);
5759
case ExecuteMode.None:
58-
await Promise.all(plugins.map(plugin => plugin[name](...args)));
60+
await Promise.all(
61+
plugins.map(plugin => this.tryExecutePlugin(plugin, name, args, null)),
62+
);
5963
return;
6064
}
6165
}
@@ -72,6 +76,14 @@ export class PluginHost {
7276
return get(this.config.plugin, key) as any;
7377
}
7478

79+
private async tryExecutePlugin(plugin: any, fnName: string, args: any[], failValue: any) {
80+
try {
81+
return await plugin[fnName](...args);
82+
} catch (e) {
83+
return failValue;
84+
}
85+
}
86+
7587
private get enabledPlugins(): any[] {
7688
return this.plugins.filter(p => this.getConfig(`${p.pluginId}.enable`));
7789
}

packages/language-server/src/plugins/SveltePlugin.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// TODO: Remove
2-
type InitialMigrationAny = any
2+
type InitialMigrationAny = any;
33

4-
import {cosmiconfig} from 'cosmiconfig';
4+
import { cosmiconfig } from 'cosmiconfig';
55
import * as prettier from 'prettier';
66
import {
77
DiagnosticsProvider,
@@ -18,7 +18,7 @@ import {
1818
import { SvelteDocument } from '../lib/documents/SvelteDocument';
1919
import { RawSourceMap, RawIndexMap, SourceMapConsumer } from 'source-map';
2020
import { CompileOptions, Warning } from 'svelte/types/compiler/interfaces';
21-
import { importSvelte, getSveltePackageInfo } from './svelte/sveltePackage';
21+
import { importSvelte } from './svelte/sveltePackage';
2222
import { PreprocessorGroup } from 'svelte/types/compiler/preprocess';
2323

2424
interface SvelteConfig extends CompileOptions {
@@ -54,9 +54,11 @@ export class SveltePlugin implements DiagnosticsProvider, FormattingProvider {
5454
const svelte = importSvelte(document.getFilePath()!);
5555

5656
const preprocessor = makePreprocessor(document as SvelteDocument, config.preprocess);
57-
source = (await svelte.preprocess(source, preprocessor, {
58-
filename: document.getFilePath()!,
59-
})).toString();
57+
source = (
58+
await svelte.preprocess(source, preprocessor, {
59+
filename: document.getFilePath()!,
60+
})
61+
).toString();
6062
preprocessor.transpiledDocument.setText(source);
6163

6264
let diagnostics: Diagnostic[];
@@ -97,9 +99,9 @@ export class SveltePlugin implements DiagnosticsProvider, FormattingProvider {
9799

98100
private async loadConfig(path: string): Promise<SvelteConfig> {
99101
try {
100-
const explorer = cosmiconfig('svelte', {packageProp: "svelte-ls"})
102+
const explorer = cosmiconfig('svelte', { packageProp: 'svelte-ls' });
101103
const result = await explorer.search(path);
102-
const config = result?.config ?? {}
104+
const config = result?.config ?? {};
103105
return { ...DEFAULT_OPTIONS, ...config };
104106
} catch (err) {
105107
return { ...DEFAULT_OPTIONS, preprocess: {} };
@@ -112,11 +114,10 @@ export class SveltePlugin implements DiagnosticsProvider, FormattingProvider {
112114
}
113115

114116
const config = await prettier.resolveConfig(document.getFilePath()!);
115-
const sveltePkg = getSveltePackageInfo(document.getFilePath()!);
116117
const formattedCode = prettier.format(document.getText(), {
117118
...config,
118119
plugins: [require.resolve('prettier-plugin-svelte')],
119-
parser: sveltePkg.version.major >= 3 ? ('svelte' as any) : 'html',
120+
parser: 'svelte' as any,
120121
});
121122

122123
return [

packages/language-server/src/plugins/TypeScriptPlugin.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,20 @@ export class TypeScriptPlugin
182182
}
183183

184184
const lang = getLanguageServiceForDocument(document, this.createDocument);
185+
// The language service throws an error if the character is not a valid trigger character.
186+
// Also, the completions are worse.
187+
// Therefore, only use the characters the typescript compiler treats as valid.
188+
const validTriggerCharacter = ['.', '"', "'", '`', '/', '@', '<', '#'].includes(
189+
triggerCharacter!,
190+
)
191+
? triggerCharacter
192+
: undefined;
185193
const completions = lang.getCompletionsAtPosition(
186194
document.getFilePath()!,
187195
document.offsetAt(position),
188196
{
189197
includeCompletionsForModuleExports: true,
190-
triggerCharacter: triggerCharacter as any,
198+
triggerCharacter: validTriggerCharacter as any,
191199
},
192200
);
193201

packages/language-server/src/plugins/svelte/sveltePackage.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ export function getSveltePackageInfo(fromPath: string) {
2121

2222
export function importSvelte(fromPath: string): typeof svelte {
2323
const pkg = getSveltePackageInfo(fromPath);
24-
25-
let main = pkg.path;
26-
if (pkg.version.major > 2) {
27-
main = resolve(pkg.path, 'compiler');
28-
}
29-
24+
const main = resolve(pkg.path, 'compiler');
3025
console.log('Using Svelte v' + pkg.version.full, 'from', main);
31-
3226
return require(main);
3327
}

packages/language-server/src/plugins/typescript/service.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ export function createLanguageService(
6464
compilerOptions,
6565
tsconfigPath,
6666
undefined,
67-
[
68-
{ extension: 'html', isMixedContent: true },
69-
{ extension: 'svelte', isMixedContent: true },
70-
],
67+
[{ extension: 'svelte', isMixedContent: true }],
7168
);
7269
files = parsedConfig.fileNames;
7370
compilerOptions = { ...compilerOptions, ...parsedConfig.options };

packages/language-server/src/plugins/typescript/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function getScriptKindFromAttributes(attrs: Record<string, string>): ts.S
3434
}
3535

3636
export function isSvelte(filePath: string) {
37-
return filePath.endsWith('.html') || filePath.endsWith('.svelte');
37+
return filePath.endsWith('.svelte');
3838
}
3939

4040
export function convertRange(

packages/language-server/test/api/Document.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,59 @@ import { TextDocument } from '../../src/lib/documents/TextDocument';
33

44
describe('Document', () => {
55
it('gets the text length', () => {
6-
const document = new TextDocument('file:///hello.html', 'Hello, world!');
6+
const document = new TextDocument('file:///hello.svelte', 'Hello, world!');
77
assert.strictEqual(document.getTextLength(), 13);
88
});
99

1010
it('updates the text range', () => {
11-
const document = new TextDocument('file:///hello.html', 'Hello, world!');
11+
const document = new TextDocument('file:///hello.svelte', 'Hello, world!');
1212
document.update('svelte', 7, 12);
1313
assert.strictEqual(document.getText(), 'Hello, svelte!');
1414
});
1515

1616
it('gets the correct position from offset', () => {
17-
const document = new TextDocument('file:///hello.html', 'Hello\nworld\n');
17+
const document = new TextDocument('file:///hello.svelte', 'Hello\nworld\n');
1818
assert.deepStrictEqual(document.positionAt(1), { line: 0, character: 1 });
1919
assert.deepStrictEqual(document.positionAt(9), { line: 1, character: 3 });
2020
assert.deepStrictEqual(document.positionAt(12), { line: 2, character: 0 });
2121
});
2222

2323
it('gets the correct offset from position', () => {
24-
const document = new TextDocument('file:///hello.html', 'Hello\nworld\n');
24+
const document = new TextDocument('file:///hello.svelte', 'Hello\nworld\n');
2525
assert.strictEqual(document.offsetAt({ line: 0, character: 1 }), 1);
2626
assert.strictEqual(document.offsetAt({ line: 1, character: 3 }), 9);
2727
assert.strictEqual(document.offsetAt({ line: 2, character: 0 }), 12);
2828
});
2929

3030
it('gets the correct position from offset with CRLF', () => {
31-
const document = new TextDocument('file:///hello.html', 'Hello\r\nworld\r\n');
31+
const document = new TextDocument('file:///hello.svelte', 'Hello\r\nworld\r\n');
3232
assert.deepStrictEqual(document.positionAt(1), { line: 0, character: 1 });
3333
assert.deepStrictEqual(document.positionAt(10), { line: 1, character: 3 });
3434
assert.deepStrictEqual(document.positionAt(14), { line: 2, character: 0 });
3535
});
3636

3737
it('gets the correct offset from position with CRLF', () => {
38-
const document = new TextDocument('file:///hello.html', 'Hello\r\nworld\r\n');
38+
const document = new TextDocument('file:///hello.svelte', 'Hello\r\nworld\r\n');
3939
assert.strictEqual(document.offsetAt({ line: 0, character: 1 }), 1);
4040
assert.strictEqual(document.offsetAt({ line: 1, character: 3 }), 10);
4141
assert.strictEqual(document.offsetAt({ line: 2, character: 0 }), 14);
4242
});
4343

4444
it('limits the position when offset is out of bounds', () => {
45-
const document = new TextDocument('file:///hello.html', 'Hello\nworld\n');
45+
const document = new TextDocument('file:///hello.svelte', 'Hello\nworld\n');
4646
assert.deepStrictEqual(document.positionAt(20), { line: 2, character: 0 });
4747
assert.deepStrictEqual(document.positionAt(-1), { line: 0, character: 0 });
4848
});
4949

5050
it('limits the offset when position is out of bounds', () => {
51-
const document = new TextDocument('file:///hello.html', 'Hello\nworld\n');
51+
const document = new TextDocument('file:///hello.svelte', 'Hello\nworld\n');
5252
assert.strictEqual(document.offsetAt({ line: 5, character: 0 }), 12);
5353
assert.strictEqual(document.offsetAt({ line: 1, character: 20 }), 12);
5454
assert.strictEqual(document.offsetAt({ line: -1, character: 0 }), 0);
5555
});
5656

5757
it('supports empty contents', () => {
58-
const document = new TextDocument('file:///hello.html', '');
58+
const document = new TextDocument('file:///hello.svelte', '');
5959
assert.strictEqual(document.offsetAt({ line: 0, character: 0 }), 0);
6060
assert.deepStrictEqual(document.positionAt(0), { line: 0, character: 0 });
6161
});

packages/language-server/test/lib/documents/DocumentFragment.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { DocumentFragment } from '../../../src/lib/documents/DocumentFragment';
44

55
describe('Document Fragment', () => {
66
it('gets the correct text', () => {
7-
const parent = new TextDocument('file:///hello.html', 'Hello, world!');
7+
const parent = new TextDocument('file:///hello.svelte', 'Hello, world!');
88
const fragment = new DocumentFragment(parent, {
99
start: 7,
1010
end: 12,
@@ -15,7 +15,7 @@ describe('Document Fragment', () => {
1515
});
1616

1717
it('returns the correct text length', () => {
18-
const parent = new TextDocument('file:///hello.html', 'Hello, world!');
18+
const parent = new TextDocument('file:///hello.svelte', 'Hello, world!');
1919
const fragment = new DocumentFragment(parent, {
2020
start: 7,
2121
end: 12,
@@ -26,7 +26,7 @@ describe('Document Fragment', () => {
2626
});
2727

2828
it('updates the parent document when setText is called', () => {
29-
const parent = new TextDocument('file:///hello.html', 'Hello, world!');
29+
const parent = new TextDocument('file:///hello.svelte', 'Hello, world!');
3030
const fragment = new DocumentFragment(parent, {
3131
start: 7,
3232
end: 12,
@@ -39,7 +39,7 @@ describe('Document Fragment', () => {
3939
});
4040

4141
it('isInFragment works', () => {
42-
const parent = new TextDocument('file:///hello.html', 'Hello, \nworld!');
42+
const parent = new TextDocument('file:///hello.svelte', 'Hello, \nworld!');
4343
const fragment = new DocumentFragment(parent, {
4444
start: 8,
4545
end: 13,
@@ -53,7 +53,7 @@ describe('Document Fragment', () => {
5353
});
5454

5555
it('calculates the offset in parent', () => {
56-
const parent = new TextDocument('file:///hello.html', 'Hello, world!');
56+
const parent = new TextDocument('file:///hello.svelte', 'Hello, world!');
5757
const fragment = new DocumentFragment(parent, {
5858
start: 7,
5959
end: 12,
@@ -64,7 +64,7 @@ describe('Document Fragment', () => {
6464
});
6565

6666
it('calculates the offset in fragment', () => {
67-
const parent = new TextDocument('file:///hello.html', 'Hello, world!');
67+
const parent = new TextDocument('file:///hello.svelte', 'Hello, world!');
6868
const fragment = new DocumentFragment(parent, {
6969
start: 7,
7070
end: 12,
@@ -75,7 +75,7 @@ describe('Document Fragment', () => {
7575
});
7676

7777
it('calculates the position in parent', () => {
78-
const parent = new TextDocument('file:///hello.html', 'Hello, \nworld!');
78+
const parent = new TextDocument('file:///hello.svelte', 'Hello, \nworld!');
7979
const fragment = new DocumentFragment(parent, {
8080
start: 8,
8181
end: 13,
@@ -89,7 +89,7 @@ describe('Document Fragment', () => {
8989
});
9090

9191
it('calculates the position in fragment', () => {
92-
const parent = new TextDocument('file:///hello.html', 'Hello, \nworld!');
92+
const parent = new TextDocument('file:///hello.svelte', 'Hello, \nworld!');
9393
const fragment = new DocumentFragment(parent, {
9494
start: 8,
9595
end: 13,
@@ -103,7 +103,7 @@ describe('Document Fragment', () => {
103103
});
104104

105105
it('returns the parent file path', () => {
106-
const parent = new TextDocument('file:///hello.html', 'Hello, world!');
106+
const parent = new TextDocument('file:///hello.svelte', 'Hello, world!');
107107
const fragment = new DocumentFragment(parent, {
108108
start: 7,
109109
end: 12,

packages/language-server/test/lib/documents/DocumentManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { DocumentManager } from '../../../src/lib/documents/DocumentManager';
66

77
describe('Document Manager', () => {
88
const textDocument: TextDocumentItem = {
9-
uri: 'file:///hello.html',
9+
uri: 'file:///hello.svelte',
1010
version: 0,
1111
languageId: '',
1212
text: 'Hello, world!',

0 commit comments

Comments
 (0)