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
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ packages/svelte2tsx/test/*/samples/*/*sx
packages/svelte2tsx/test/*/samples/*/*.svelte
packages/svelte2tsx/test/sourcemaps/*.html
packages/language-server/test/**/*.svelte
packages/language-server/test/**/testfiles/**/*.ts
packages/svelte-vscode/syntaxes/*.yaml
**/dist
.github/**
.history/**
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"typescript.preferences.quoteStyle": "single",
"typescript.preferences.quoteStyle": "single"
}
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ A `.svelte` file would look something like this:
}
</script>

<button on:click="{handleClick}">
Count: {count}
</button>
<button on:click="{handleClick}">Count: {count}</button>

<p>{count} * 2 = {doubled}</p>
<p>{doubled} * 2 = {quadrupled}</p>
Expand Down Expand Up @@ -128,7 +126,7 @@ For tricker issues, you can run the tests with a debugger in VSCode by setting a

Svelte is an MIT-licensed open source project with its ongoing development made possible entirely by the support of awesome volunteers. If you'd like to support their efforts, please consider:

- [Becoming a backer on Open Collective](https://opencollective.com/svelte).
- [Becoming a backer on Open Collective](https://opencollective.com/svelte).

Funds donated via Open Collective will be used for compensating expenses related to Svelte's development such as hosting costs. If sufficient donations are received, funds may also be used to support Svelte's development more directly.

Expand Down
11 changes: 5 additions & 6 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ LSP-compatible editors, you can use an HTML comment with the `@component` tag:
<!-- @component But only the last documentation comment will be used -->

<main>
<h1>
Hello world
</h1>
<h1>Hello world</h1>
</main>
```

Expand All @@ -66,7 +64,7 @@ The VS Code extension comes with its own syntax highlighting grammar which defin
}
```

To find out the scope of the things you want to highlight differently, you can use the scope inspector by entering the command "Developer: Inspect Editor Tokens and Scopes". The scope at the top of the section "textmate scopes" is what you are looking for. The current color is in the section "foreground" - you can use this to look up colors of other scopes if you want them to be the same color but don't know the color-code.
To find out the scope of the things you want to highlight differently, you can use the scope inspector by entering the command "Developer: Inspect Editor Tokens and Scopes". The scope at the top of the section "textmate scopes" is what you are looking for. The current color is in the section "foreground" - you can use this to look up colors of other scopes if you want them to be the same color but don't know the color-code.

For more info on customizing your theme, [see the VS Code docs](https://code.visualstudio.com/docs/getstarted/themes#_customizing-a-color-theme).

Expand Down Expand Up @@ -95,8 +93,9 @@ If you have the `Babel Javascript` plugin installed, this may be the cause. Disa
#### My Code does not get formatted

Your default formatter for Svelte files may be wrong.
- Mabye it's set to the old Svelte extension, if so, remove the setting
- Maybe you set all files to be formatted by the prettier extension. Then you have two options: Either install `prettier-plugin-svelte` from npm, or tell VSCode to format the code with the `Svelte for VSCode extension`:

- Mabye it's set to the old Svelte extension, if so, remove the setting
- Maybe you set all files to be formatted by the prettier extension. Then you have two options: Either install `prettier-plugin-svelte` from npm, or tell VSCode to format the code with the `Svelte for VSCode extension`:

```json
"[svelte]": {
Expand Down
8 changes: 4 additions & 4 deletions docs/internal/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

The [publisher is Svelte](https://marketplace.visualstudio.com/manage/publishers/svelte)

- Extension builds with the account signed up via GitHub from orta
- Extension builds with the account signed up via GitHub from orta

### npm deployments

- Deployments come from a bot: `svelte-language-tools-deploy`
- Deployments come from a bot: `svelte-language-tools-deploy`

### When Deployments happen

- Nightly builds are triggered through a scheduled GitHub workflow every night at 04:00 UTC.
- Production builds are triggered by creating a new tag, which is best done through the "do a release" on Github. The tag name equals the version that is then shown on the marketplace, so each tag should have a higher version than the previous.
- Nightly builds are triggered through a scheduled GitHub workflow every night at 04:00 UTC.
- Production builds are triggered by creating a new tag, which is best done through the "do a release" on Github. The tag name equals the version that is then shown on the marketplace, so each tag should have a higher version than the previous.
2 changes: 1 addition & 1 deletion docs/internal/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ We chose the second option because TypeScript provides a language service which

`svelte2tsx` uses some [ambient definitions](/packages/svelte2tsx/svelte-shims.d.ts) which are loaded by the language server to do some of the transformations. It also provides [JSX definitions](/packages/svelte2tsx/svelte-jsx.d.ts) which are recognized by the TypeScript compiler and define intrinsic elements, attributes and events - so if you ever get an error that a DOM attribute is not assignable to a DOM element, it's likely a missing declaration in there.

The code generated by `svelte2tsx` is not runnable in any way and does not actually exist at runtime when you run your app, it purely exists for the IntelliSense.
The code generated by `svelte2tsx` is not runnable in any way and does not actually exist at runtime when you run your app, it purely exists for the IntelliSense.

The code also returns source mappings so we know which position in the original code corresponds to which generated position.

Expand Down
20 changes: 10 additions & 10 deletions docs/preprocessors/in-general.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

If a svelte file contains some language other than `html`, `css` or `javascript`, `svelte-vscode` needs to know how to [preprocess](https://svelte.dev/docs#svelte_preprocess) it. This can be achieved by creating a `svelte.config.js` file at the root of your project which exports a svelte options object (similar to `svelte-loader` and `rollup-plugin-svelte`). It's recommended to use the official [svelte-preprocess](https://github.com/sveltejs/svelte-preprocess) package which can handle many languages.

> NOTE: you __cannot__ use the new `import x from y` and `export const` / `export default` syntax in `svelte.config.js`.
> NOTE: you **cannot** use the new `import x from y` and `export const` / `export default` syntax in `svelte.config.js`.

```js
// svelte.config.js
const sveltePreprocess = require('svelte-preprocess');

module.exports = {
preprocess: sveltePreprocess(),
preprocess: sveltePreprocess()
};
```

Expand Down Expand Up @@ -46,9 +46,9 @@ const sveltePreprocess = require('svelte-preprocess');
module.exports = {
preprocess: sveltePreprocess({
defaults: {
script: 'typescript', // <-- now you can just write <script>let typingsAllowed: string;</script>
},
}),
script: 'typescript' // <-- now you can just write <script>let typingsAllowed: string;</script>
}
})
};
```

Expand All @@ -63,14 +63,14 @@ const sveltePreprocess = require('svelte-preprocess');
// using sourceMap as an example, but could be anything you need dynamically
function createPreprocessors(sourceMap) {
return sveltePreprocess({
sourceMap,
sourceMap
// ... your settings
});
}

module.exports = {
preprocess: createPreprocessors(true),
createPreprocessors,
createPreprocessors
};
```

Expand All @@ -88,10 +88,10 @@ export default {
// ...
svelte({
// ...
preprocess: createPreprocessors(!production),
}),
preprocess: createPreprocessors(!production)
})
// ...
],
]
};
```

Expand Down
4 changes: 2 additions & 2 deletions docs/preprocessors/scss-less.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ You need a `svelte.config.js`. [Read here on how to set it up and also how it re
const sveltePreprocess = require('svelte-preprocess');

module.exports = {
preprocess: sveltePreprocess(),
preprocess: sveltePreprocess()
};
```

Expand Down Expand Up @@ -76,6 +76,6 @@ const sveltePreprocess = require('svelte-preprocess');
const path = require('path');

module.exports = {
preprocess: sveltePreprocess({ includePaths: [path.join(__dirname, 'relative/path')] })
preprocess: sveltePreprocess({ includePaths: [path.join(__dirname, 'relative/path')] })
};
```
2 changes: 1 addition & 1 deletion docs/preprocessors/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ You may optionally want to add a `svelte.config.js` file - but it is not require
const sveltePreprocess = require('svelte-preprocess');

module.exports = {
preprocess: sveltePreprocess(),
preprocess: sveltePreprocess()
};
```

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"build": "tsc -b",
"test": "CI=true yarn workspaces run test",
"watch": "tsc -b -watch",
"lint": "eslint \"packages/**/*.{ts,js}\""
"format": "prettier --write .",
"lint": "prettier --check . && eslint \"packages/**/*.{ts,js}\""
},
"dependencies": {
"axios": "0.21.1",
"typescript": "^4.1.3"
},
"devDependencies": {
Expand All @@ -24,6 +24,7 @@
"@typescript-eslint/parser": "^4.3.0",
"eslint": "^7.7.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-svelte3": "^2.7.3"
"eslint-plugin-svelte3": "^2.7.3",
"prettier": "2.2.1"
}
}
2 changes: 1 addition & 1 deletion packages/language-server/src/ls-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export interface LSTypescriptConfig {
};
semanticTokens: {
enable: boolean;
}
};
}

export interface LSCSSConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { IPseudoClassData } from 'vscode-css-languageservice';
export const pesudoClass: IPseudoClassData[] = [
{
name: ':global()',
description:
`[svelte] :global modifier
description: `[svelte] :global modifier

Applying styles to a selector globally`,
references: [
Expand Down
11 changes: 8 additions & 3 deletions packages/language-server/src/plugins/css/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ const customDataProvider: ICSSDataProvider = {
}
};

const [css, scss, less] = [getCSSLanguageService, getSCSSLanguageService, getLESSLanguageService]
.map(getService => getService({
const [css, scss, less] = [
getCSSLanguageService,
getSCSSLanguageService,
getLESSLanguageService
].map((getService) =>
getService({
customDataProviders: [customDataProvider]
}));
})
);

const langs = {
css,
Expand Down
6 changes: 3 additions & 3 deletions packages/language-server/src/plugins/html/dataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ const mediaAttributes: IAttributeData[] = [
},
{
name: 'bind:playbackRate',
description: 'how fast or slow to play the video, where 1 is \'normal\''
description: "how fast or slow to play the video, where 1 is 'normal'"
},
{
name: 'bind:paused'
Expand Down Expand Up @@ -256,14 +256,14 @@ const addAttributes: Record<string, IAttributeData[]> = {
{ name: 'bind:value' },
{ name: 'bind:group', description: 'Available for type="radio" and type="checkbox"' },
indeterminateAttribute,
{...indeterminateAttribute, name: 'bind:indeterminate'}
{ ...indeterminateAttribute, name: 'bind:indeterminate' }
],
textarea: [{ name: 'bind:value' }],
video: [...mediaAttributes, ...videoAttributes],
audio: [...mediaAttributes]
};

const html5Tags = htmlData.tags!.map(tag => {
const html5Tags = htmlData.tags!.map((tag) => {
let attributes = tag.attributes.map(mapToSvelteEvent);
if (addAttributes[tag.name]) {
attributes = [...attributes, ...addAttributes[tag.name]];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ export class LSAndTSDocResolver {
}

private getUserPreferences(scriptKind: ts.ScriptKind): ts.UserPreferences {
const configLang = scriptKind === ts.ScriptKind.TS || scriptKind === ts.ScriptKind.TSX
? 'typescript' : 'javascript';
const configLang =
scriptKind === ts.ScriptKind.TS || scriptKind === ts.ScriptKind.TSX
? 'typescript'
: 'javascript';

return this.configManager.getTsUserPreferences(configLang);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ export class SelectionRangeProviderImpl implements SelectionRangeProvider {
};
}

private filterOutUnmappedRange(
selectionRange: SelectionRange
): SelectionRange | null {
private filterOutUnmappedRange(selectionRange: SelectionRange): SelectionRange | null {
const flattened = this.flattenAndReverseSelectionRange(selectionRange);
const filtered = flattened.filter((range) => range.start.line > 0 && range.end.line > 0);
if (!filtered.length) {
Expand All @@ -54,7 +52,6 @@ export class SelectionRangeProviderImpl implements SelectionRangeProvider {
return result ?? null;
}


/**
* flatten the selection range and its parent to an array in reverse order
* so it's easier to filter out unmapped selection and create a new tree of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import ts from 'typescript';
import {
Range,
SemanticTokens,
SemanticTokensBuilder
} from 'vscode-languageserver';
import { Range, SemanticTokens, SemanticTokensBuilder } from 'vscode-languageserver';
import { Document } from '../../../lib/documents';
import { SemanticTokensProvider } from '../../interfaces';
import { SnapshotFragment } from '../DocumentSnapshot';
Expand Down Expand Up @@ -65,7 +61,7 @@ export class SemanticTokensProviderImpl implements SemanticTokensProvider {

const modifier = this.getTokenModifierFromClassification(encodedClassification);

builder.push(line, character, length, classificationType , modifier);
builder.push(line, character, length, classificationType, modifier);
}

return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { LSAndTSDocResolver } from '../LSAndTSDocResolver';
import { getMarkdownDocumentation } from '../previewer';

export class SignatureHelpProviderImpl implements SignatureHelpProvider {
constructor(private readonly lsAndTsDocResolver: LSAndTSDocResolver) { }
constructor(private readonly lsAndTsDocResolver: LSAndTSDocResolver) {}

private static readonly triggerCharacters = ['(', ',', '<'];
private static readonly retriggerCharacters = [')'];
Expand All @@ -41,8 +41,7 @@ export class SignatureHelpProviderImpl implements SignatureHelpProvider {
return null;
}

const signatures = info.items
.map(this.toSignatureHelpInformation);
const signatures = info.items.map(this.toSignatureHelpInformation);

return {
signatures,
Expand Down Expand Up @@ -134,18 +133,19 @@ export class SignatureHelpProviderImpl implements SignatureHelpProvider {

return {
label: prefixLabel + signatureLabel + suffixLabel,
documentation: signatureDocumentation ? {
value: signatureDocumentation,
kind: MarkupKind.Markdown
} : undefined,
documentation: signatureDocumentation
? {
value: signatureDocumentation,
kind: MarkupKind.Markdown
}
: undefined,
parameters
};
}

private isInSvelte2tsxGeneratedFunction(
signatureHelpItem: ts.SignatureHelpItem
) {
return signatureHelpItem.prefixDisplayParts
.some((part) => part.text.includes('__sveltets'));
private isInSvelte2tsxGeneratedFunction(signatureHelpItem: ts.SignatureHelpItem) {
return signatureHelpItem.prefixDisplayParts.some((part) =>
part.text.includes('__sveltets')
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import {
export const tsDirectives = [
{
value: '@ts-check',
description:
'Enables semantic checking in a JavaScript file. Must be at the top of a file.'
description: 'Enables semantic checking in a JavaScript file. Must be at the top of a file.'
},
{
value: '@ts-nocheck',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ export function createSvelteSys(getSnapshot: (fileName: string) => DocumentSnaps
readDirectory(path, extensions, exclude, include, depth) {
const extensionsWithSvelte = (extensions ?? []).concat('.svelte');

return ts.sys.readDirectory(
path,
extensionsWithSvelte,
exclude,
include,
depth
);
return ts.sys.readDirectory(path, extensionsWithSvelte, exclude, include, depth);
}
};

Expand Down
2 changes: 1 addition & 1 deletion packages/language-server/src/plugins/typescript/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function findTsConfigPath(fileName: string, rootUris: string[]) {
ts.findConfigFile(searchDir, ts.sys.fileExists, 'jsconfig.json') ||
'';
// Don't return config files that exceed the current workspace context.
return !!path && rootUris.some(rootUri => isSubPath(rootUri, path)) ? path : '';
return !!path && rootUris.some((rootUri) => isSubPath(rootUri, path)) ? path : '';
}

export function isSubPath(uri: string, possibleSubPath: string): boolean {
Expand Down
Loading