Skip to content

Commit 46ae655

Browse files
committed
Merge branch 'master' of https://github.com/sveltejs/language-tools into html-auto-close
2 parents 67d56ab + bbb894e commit 46ae655

31 files changed

+655
-140
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
## What is Svelte Language Tools?
1717

18+
Svelte Language Tools contains a library implementing the Language Server Protocol (LSP). LSP powers the [VSCode extension](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode), which is also hosted in this repository. Additionally, LSP is capable of powering plugins for [numerous other IDEs](https://microsoft.github.io/language-server-protocol/implementors/tools/
19+
).
20+
1821
A `.svelte` file would look something like this:
1922

2023
```html
@@ -86,14 +89,13 @@ There are two ways to work on this project: either by working against an existin
8689

8790
## Running the Dev Language Server Against Your App
8891

89-
To run the developer version of both the language server and the vscode extension:
92+
To run the developer version of both the language server and the VSCode extension:
9093

91-
- open the root of this repo in VS Code
94+
- open the root of this repo in VSCode
9295
- Go to the debugging panel
9396
- Make sure "Run VSCode Extension" is selected, and hit run
9497

95-
This launches a new vscode window and a watcher for your changes.
96-
In this dev window you can choose an existing Svelte project to work against, when you make changes to the extension or language server you can use the command "Reload Window" in the VS Code command palette to see you changes.
98+
This launches a new VSCode window and a watcher for your changes. In this dev window you can choose an existing Svelte project to work against. If you don't use pure Javascript and CSS, but languages like Typescript or SCSS, your project will need a [Svelte preprocessor setup](packages/svelte-vscode#using-with-preprocessors). When you make changes to the extension or language server you can use the command "Reload Window" in the VSCode command palette to see your changes.
9799

98100
### Running Tests
99101

docs/deployment.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### VS Code deployments
2+
3+
The [publisher is Svelte](https://marketplace.visualstudio.com/manage/publishers/svelte)
4+
5+
- Extension builds with the account signed up via GitHub from orta
6+
7+
### npm deployments
8+
9+
- Deployments come from a bot: `svelte-language-tools-deploy`

packages/language-server/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
"estree-walker": "^2.0.1",
5151
"lodash": "^4.17.10",
5252
"magic-string": "^0.25.3",
53-
"prettier": "1.19.1",
54-
"prettier-plugin-svelte": "0.7.0",
53+
"prettier": "2.0.5",
54+
"prettier-plugin-svelte": "1.1.0",
5555
"source-map": "^0.7.3",
5656
"svelte": "3.19.2",
5757
"typescript": "*",

packages/language-server/src/lib/documents/Document.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export abstract class Document implements TextDocument {
118118
return this.getText().split(/\r?\n/).length;
119119
}
120120

121-
languageId = '';
121+
abstract languageId: string;
122122
}
123123

124124
/**

packages/language-server/src/lib/documents/ManagedDocument.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { WritableDocument } from './Document';
55
* Represents a text document that contains a svelte component.
66
*/
77
export class ManagedDocument extends WritableDocument {
8+
9+
public languageId = 'svelte';
10+
811
constructor(public url: string, public content: string) {
912
super();
1013
}

packages/language-server/src/lib/documents/TextDocument.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { urlToPath } from '../../utils';
22
import { WritableDocument } from './Document';
33

44
export class TextDocument extends WritableDocument {
5+
6+
public languageId = 'svelte';
7+
58
constructor(public url: string, public content: string) {
69
super();
710
}

packages/language-server/src/lib/documents/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function parseAttributes(str: string): Record<string, string> {
2424
* @param tag the tag to extract
2525
*/
2626
export function extractTag(source: string, tag: 'script' | 'style') {
27-
const exp = new RegExp(`(<!--.*-->)|(<${tag}([\\S\\s]*?)>)([\\S\\s]*?)<\\/${tag}>`, 'igs');
27+
const exp = new RegExp(`(<!--.*-->)|(<${tag}(\\s[\\S\\s]*?)?>)([\\S\\s]*?)<\\/${tag}>`, 'igs');
2828
let match = exp.exec(source);
2929

3030
while (match && match[0].startsWith('<!--')) {
@@ -35,7 +35,7 @@ export function extractTag(source: string, tag: 'script' | 'style') {
3535
return null;
3636
}
3737

38-
const attributes = parseAttributes(match[3]);
38+
const attributes = parseAttributes(match[3] || '');
3939
const content = match[4];
4040
const start = match.index + match[2].length;
4141
const end = start + content.length;

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ import {
1515
TextDocumentIdentifier,
1616
TextEdit,
1717
FileChangeType,
18+
CompletionItem,
1819
} from 'vscode-languageserver';
1920
import { LSConfig, LSConfigManager } from '../ls-config';
2021
import { DocumentManager } from '../lib/documents';
21-
import { LSProvider, Plugin, OnWatchFileChanges } from './interfaces';
22+
import { LSProvider, Plugin, OnWatchFileChanges, AppCompletionItem } from './interfaces';
2223

2324
enum ExecuteMode {
2425
None,
@@ -88,6 +89,26 @@ export class PluginHost implements LSProvider, OnWatchFileChanges {
8889
);
8990
}
9091

92+
async resolveCompletion(
93+
textDocument: TextDocumentIdentifier,
94+
completionItem: AppCompletionItem
95+
): Promise<CompletionItem> {
96+
const document = this.getDocument(textDocument.uri);
97+
98+
if (!document) {
99+
throw new Error('Cannot call methods on an unopened document');
100+
}
101+
102+
const result = await this.execute<CompletionItem>(
103+
'resolveCompletion',
104+
[document, completionItem],
105+
ExecuteMode.FirstNonNull
106+
);
107+
108+
return result ?? completionItem;
109+
}
110+
111+
91112
async formatDocument(textDocument: TextDocumentIdentifier): Promise<TextEdit[]> {
92113
const document = this.getDocument(textDocument.uri);
93114
if (!document) {

packages/language-server/src/plugins/css/CSSDocument.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export class CSSFragment {
6666
export class CSSDocument extends Document implements Fragment {
6767
private cssFragment: CSSFragment;
6868
public stylesheet: Stylesheet;
69+
public languageId = 'css';
6970

7071
constructor(private parent: Document) {
7172
super();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { IPseudoClassData } from 'vscode-css-languageservice';
2+
3+
export const pesudoClass: IPseudoClassData[] = [
4+
{
5+
name: ':global()',
6+
description:
7+
`[svelte] :global modifier
8+
9+
Applying styles to a selector globally`,
10+
references: [
11+
{
12+
name: 'Svelte.dev Reference',
13+
url: 'https://svelte.dev/docs#style'
14+
}
15+
]
16+
},
17+
];

0 commit comments

Comments
 (0)