Skip to content

Commit 28dfebe

Browse files
feat: Update to Volar 2.4.0 (#938)
* feat: Update to Volar 2.4.0 * Update init.test.ts * Update init.test.ts * Update server.ts * chore: changeset --------- Co-authored-by: Princesseuh <[email protected]>
1 parent b52c0f4 commit 28dfebe

File tree

13 files changed

+153
-147
lines changed

13 files changed

+153
-147
lines changed

.changeset/tender-jobs-tickle.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@astrojs/language-server": patch
3+
"@astrojs/check": patch
4+
"@astrojs/ts-plugin": patch
5+
"@astrojs/yaml2ts": patch
6+
"astro-vscode": patch
7+
---
8+
9+
Updates to the stable version of Volar 2.4.0

packages/astro-check/src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ export async function check(flags: Partial<Flags>): Promise<boolean | void> {
3939

4040
// Dynamically get the list of extensions to watch from the files already included in the project
4141
const checkedExtensions = Array.from(
42-
new Set(
43-
checker.linter.projectHost.getScriptFileNames().map((fileName) => path.extname(fileName)),
44-
),
42+
new Set(checker.linter.getRootFileNames().map((fileName) => path.extname(fileName))),
4543
);
4644
createWatcher(workspaceRoot, checkedExtensions)
4745
.on('add', (fileName) => {

packages/language-server/package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@
3030
"@astrojs/compiler": "^2.10.3",
3131
"@astrojs/yaml2ts": "^0.2.0",
3232
"@jridgewell/sourcemap-codec": "^1.4.15",
33-
"@volar/kit": "~2.4.0-alpha.15",
34-
"@volar/language-core": "~2.4.0-alpha.15",
35-
"@volar/language-server": "~2.4.0-alpha.15",
36-
"@volar/language-service": "~2.4.0-alpha.15",
37-
"@volar/typescript": "~2.4.0-alpha.15",
33+
"@volar/kit": "~2.4.0",
34+
"@volar/language-core": "~2.4.0",
35+
"@volar/language-server": "~2.4.0",
36+
"@volar/language-service": "~2.4.0",
37+
"@volar/typescript": "~2.4.0",
3838
"fast-glob": "^3.2.12",
3939
"muggle-string": "^0.4.1",
40-
"volar-service-css": "0.0.59",
41-
"volar-service-emmet": "0.0.59",
42-
"volar-service-html": "0.0.59",
43-
"volar-service-prettier": "0.0.59",
44-
"volar-service-typescript": "0.0.59",
45-
"volar-service-typescript-twoslash-queries": "0.0.59",
46-
"volar-service-yaml": "0.0.59",
40+
"volar-service-css": "0.0.61",
41+
"volar-service-emmet": "0.0.61",
42+
"volar-service-html": "0.0.61",
43+
"volar-service-prettier": "0.0.61",
44+
"volar-service-typescript": "0.0.61",
45+
"volar-service-typescript-twoslash-queries": "0.0.61",
46+
"volar-service-yaml": "0.0.61",
4747
"vscode-html-languageservice": "^5.2.0",
4848
"vscode-uri": "^3.0.8"
4949
},
@@ -53,7 +53,7 @@
5353
"@types/chai": "^4.3.5",
5454
"@types/mocha": "^10.0.1",
5555
"@types/node": "^18.17.8",
56-
"@volar/test-utils": "~2.4.0-alpha.15",
56+
"@volar/test-utils": "~2.4.0",
5757
"astro": "^4.14.0",
5858
"chai": "^4.3.7",
5959
"mocha": "^10.2.0",

packages/language-server/src/check.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { pathToFileURL } from 'node:url';
55
import * as kit from '@volar/kit';
66
import { Diagnostic, DiagnosticSeverity } from '@volar/language-server';
77
import fg from 'fast-glob';
8+
import { URI } from 'vscode-uri';
89
import { getAstroLanguagePlugin } from './core/index.js';
910
import { getSvelteLanguagePlugin } from './core/svelte.js';
1011
import { getVueLanguagePlugin } from './core/vue.js';
@@ -61,13 +62,13 @@ export class AstroCheck {
6162
}
6263
| undefined;
6364
}): Promise<CheckResult> {
64-
let files = (
65-
fileNames !== undefined ? fileNames : this.linter.projectHost.getScriptFileNames()
66-
).filter((file) => {
67-
// We don't have the same understanding of Svelte and Vue files as their own respective tools (vue-tsc, svelte-check)
68-
// So we don't want to check them here
69-
return !file.endsWith('.vue') && !file.endsWith('.svelte');
70-
});
65+
let files = (fileNames !== undefined ? fileNames : this.linter.getRootFileNames()).filter(
66+
(file) => {
67+
// We don't have the same understanding of Svelte and Vue files as their own respective tools (vue-tsc, svelte-check)
68+
// So we don't want to check them here
69+
return !file.endsWith('.vue') && !file.endsWith('.svelte');
70+
},
71+
);
7172

7273
const result: CheckResult = {
7374
status: undefined,
@@ -104,7 +105,7 @@ export class AstroCheck {
104105
console.info(errorText);
105106
}
106107

107-
const fileSnapshot = this.linter.projectHost.getScriptSnapshot(file);
108+
const fileSnapshot = this.linter.language.scripts.get(URI.file(file))?.snapshot;
108109
const fileContent = fileSnapshot?.getText(0, fileSnapshot.getLength());
109110

110111
result.fileResult.push({
@@ -145,7 +146,13 @@ export class AstroCheck {
145146
const services = [...createTypeScriptServices(this.ts), createAstroService(this.ts)];
146147

147148
if (tsconfigPath) {
148-
this.linter = kit.createTypeScriptChecker(languagePlugins, services, tsconfigPath);
149+
const includeProjectReference = false; // #920
150+
this.linter = kit.createTypeScriptChecker(
151+
languagePlugins,
152+
services,
153+
tsconfigPath,
154+
includeProjectReference,
155+
);
149156
} else {
150157
this.linter = kit.createTypeScriptInferredChecker(languagePlugins, services, () => {
151158
return fg.sync('**/*.astro', {

packages/language-server/src/nodeServer.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ connection.onInitialize((params) => {
4141
collectionConfigs = folders.flatMap((folder) => {
4242
try {
4343
const folderUri = URI.parse(folder.uri);
44-
let config = server.fs.readFile(
44+
let config = server.fileSystem.readFile(
4545
Utils.joinPath(folderUri, '.astro/collections/collections.json'),
4646
);
4747

@@ -76,7 +76,6 @@ connection.onInitialize((params) => {
7676
};
7777
}),
7878
getLanguageServicePlugins(connection, typescript, collectionConfigs),
79-
{ pullModelDiagnostics: params.initializationOptions?.pullModelDiagnostics },
8079
);
8180
});
8281

@@ -102,5 +101,5 @@ connection.onInitialized(() => {
102101
extensions.push(...SUPPORTED_FRONTMATTER_EXTENSIONS_KEYS);
103102
}
104103

105-
server.watchFiles([`**/*.{${extensions.join(',')}}`]);
104+
server.fileWatcher.watchFiles([`**/*.{${extensions.join(',')}}`]);
106105
});

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ export const create = (ts: typeof import('typescript')): LanguageServicePlugin =
2727
completionProvider: {
2828
triggerCharacters: ['-'],
2929
},
30-
diagnosticProvider: {},
30+
diagnosticProvider: {
31+
interFileDependencies: false,
32+
workspaceDiagnostics: false,
33+
},
3134
codeLensProvider: {},
3235
},
3336
create(context): LanguageServicePluginInstance {
@@ -51,7 +54,7 @@ export const create = (ts: typeof import('typescript')): LanguageServicePlugin =
5154
items: items,
5255
};
5356
},
54-
provideSemanticDiagnostics(document, token) {
57+
provideDiagnostics(document, token) {
5558
if (token.isCancellationRequested) return [];
5659

5760
const decoded = context.decodeEmbeddedDocumentUri(URI.parse(document.uri));

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const create = (ts: typeof import('typescript')): LanguageServicePlugin[]
5656

5757
return enhancedResolveCodeAction(resolvedCodeAction, context);
5858
},
59-
async provideSemanticDiagnostics(document, token) {
59+
async provideDiagnostics(document, token) {
6060
const decoded = context.decodeEmbeddedDocumentUri(URI.parse(document.uri));
6161
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
6262
const root = sourceScript?.generated?.root;
@@ -70,10 +70,7 @@ export const create = (ts: typeof import('typescript')): LanguageServicePlugin[]
7070
tsxLineCount = root.astroMeta.tsxRanges.body.end.line;
7171
}
7272

73-
const diagnostics = await typeScriptPlugin.provideSemanticDiagnostics!(
74-
document,
75-
token,
76-
);
73+
const diagnostics = await typeScriptPlugin.provideDiagnostics!(document, token);
7774
if (!diagnostics) return null;
7875

7976
return enhancedProvideSemanticDiagnostics(diagnostics, tsxLineCount);

packages/language-server/test/misc/init.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ describe('Initialize', async () => {
6464
],
6565
},
6666
definitionProvider: true,
67-
diagnosticProvider: {
68-
interFileDependencies: true,
69-
workspaceDiagnostics: false,
70-
},
7167
documentFormattingProvider: true,
7268
documentHighlightProvider: true,
7369
documentLinkProvider: {},
@@ -87,7 +83,7 @@ describe('Initialize', async () => {
8783
triggerCharacters: ['=', '>', '/'],
8884
},
8985
fileReferencesProvider: true,
90-
fileRenameProvider: true,
86+
fileRenameEditsProvider: true,
9187
},
9288
foldingRangeProvider: true,
9389
hoverProvider: true,

packages/language-server/test/server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ export async function getLanguageServer(): Promise<LanguageServer> {
3535
'lib',
3636
),
3737
},
38-
pullModelDiagnostics: true,
3938
contentIntellisense: true,
4039
},
4140
{
41+
textDocument: {
42+
definition: {
43+
linkSupport: true,
44+
},
45+
},
4246
workspace: {
4347
// Needed for tests that use didChangeWatchedFiles
4448
didChangeWatchedFiles: {},

packages/ts-plugin/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"@astrojs/compiler": "^2.10.3",
3131
"@astrojs/yaml2ts": "^0.2.0",
3232
"@jridgewell/sourcemap-codec": "^1.4.15",
33-
"@volar/language-core": "~2.4.0-alpha.15",
34-
"@volar/typescript": "~2.4.0-alpha.15",
33+
"@volar/language-core": "~2.4.0",
34+
"@volar/typescript": "~2.4.0",
3535
"semver": "^7.3.8",
3636
"vscode-languageserver-textdocument": "^1.0.11"
3737
},

0 commit comments

Comments
 (0)