Skip to content

Commit

Permalink
feat: Update to Volar 2.4.0 (#938)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
johnsoncodehk and Princesseuh authored Aug 18, 2024
1 parent b52c0f4 commit 28dfebe
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 147 deletions.
9 changes: 9 additions & 0 deletions .changeset/tender-jobs-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@astrojs/language-server": patch
"@astrojs/check": patch
"@astrojs/ts-plugin": patch
"@astrojs/yaml2ts": patch
"astro-vscode": patch
---

Updates to the stable version of Volar 2.4.0
4 changes: 1 addition & 3 deletions packages/astro-check/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ export async function check(flags: Partial<Flags>): Promise<boolean | void> {

// Dynamically get the list of extensions to watch from the files already included in the project
const checkedExtensions = Array.from(
new Set(
checker.linter.projectHost.getScriptFileNames().map((fileName) => path.extname(fileName)),
),
new Set(checker.linter.getRootFileNames().map((fileName) => path.extname(fileName))),
);
createWatcher(workspaceRoot, checkedExtensions)
.on('add', (fileName) => {
Expand Down
26 changes: 13 additions & 13 deletions packages/language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@
"@astrojs/compiler": "^2.10.3",
"@astrojs/yaml2ts": "^0.2.0",
"@jridgewell/sourcemap-codec": "^1.4.15",
"@volar/kit": "~2.4.0-alpha.15",
"@volar/language-core": "~2.4.0-alpha.15",
"@volar/language-server": "~2.4.0-alpha.15",
"@volar/language-service": "~2.4.0-alpha.15",
"@volar/typescript": "~2.4.0-alpha.15",
"@volar/kit": "~2.4.0",
"@volar/language-core": "~2.4.0",
"@volar/language-server": "~2.4.0",
"@volar/language-service": "~2.4.0",
"@volar/typescript": "~2.4.0",
"fast-glob": "^3.2.12",
"muggle-string": "^0.4.1",
"volar-service-css": "0.0.59",
"volar-service-emmet": "0.0.59",
"volar-service-html": "0.0.59",
"volar-service-prettier": "0.0.59",
"volar-service-typescript": "0.0.59",
"volar-service-typescript-twoslash-queries": "0.0.59",
"volar-service-yaml": "0.0.59",
"volar-service-css": "0.0.61",
"volar-service-emmet": "0.0.61",
"volar-service-html": "0.0.61",
"volar-service-prettier": "0.0.61",
"volar-service-typescript": "0.0.61",
"volar-service-typescript-twoslash-queries": "0.0.61",
"volar-service-yaml": "0.0.61",
"vscode-html-languageservice": "^5.2.0",
"vscode-uri": "^3.0.8"
},
Expand All @@ -53,7 +53,7 @@
"@types/chai": "^4.3.5",
"@types/mocha": "^10.0.1",
"@types/node": "^18.17.8",
"@volar/test-utils": "~2.4.0-alpha.15",
"@volar/test-utils": "~2.4.0",
"astro": "^4.14.0",
"chai": "^4.3.7",
"mocha": "^10.2.0",
Expand Down
25 changes: 16 additions & 9 deletions packages/language-server/src/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { pathToFileURL } from 'node:url';
import * as kit from '@volar/kit';
import { Diagnostic, DiagnosticSeverity } from '@volar/language-server';
import fg from 'fast-glob';
import { URI } from 'vscode-uri';
import { getAstroLanguagePlugin } from './core/index.js';
import { getSvelteLanguagePlugin } from './core/svelte.js';
import { getVueLanguagePlugin } from './core/vue.js';
Expand Down Expand Up @@ -61,13 +62,13 @@ export class AstroCheck {
}
| undefined;
}): Promise<CheckResult> {
let files = (
fileNames !== undefined ? fileNames : this.linter.projectHost.getScriptFileNames()
).filter((file) => {
// We don't have the same understanding of Svelte and Vue files as their own respective tools (vue-tsc, svelte-check)
// So we don't want to check them here
return !file.endsWith('.vue') && !file.endsWith('.svelte');
});
let files = (fileNames !== undefined ? fileNames : this.linter.getRootFileNames()).filter(
(file) => {
// We don't have the same understanding of Svelte and Vue files as their own respective tools (vue-tsc, svelte-check)
// So we don't want to check them here
return !file.endsWith('.vue') && !file.endsWith('.svelte');
},
);

const result: CheckResult = {
status: undefined,
Expand Down Expand Up @@ -104,7 +105,7 @@ export class AstroCheck {
console.info(errorText);
}

const fileSnapshot = this.linter.projectHost.getScriptSnapshot(file);
const fileSnapshot = this.linter.language.scripts.get(URI.file(file))?.snapshot;
const fileContent = fileSnapshot?.getText(0, fileSnapshot.getLength());

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

if (tsconfigPath) {
this.linter = kit.createTypeScriptChecker(languagePlugins, services, tsconfigPath);
const includeProjectReference = false; // #920
this.linter = kit.createTypeScriptChecker(
languagePlugins,
services,
tsconfigPath,
includeProjectReference,
);
} else {
this.linter = kit.createTypeScriptInferredChecker(languagePlugins, services, () => {
return fg.sync('**/*.astro', {
Expand Down
5 changes: 2 additions & 3 deletions packages/language-server/src/nodeServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ connection.onInitialize((params) => {
collectionConfigs = folders.flatMap((folder) => {
try {
const folderUri = URI.parse(folder.uri);
let config = server.fs.readFile(
let config = server.fileSystem.readFile(
Utils.joinPath(folderUri, '.astro/collections/collections.json'),
);

Expand Down Expand Up @@ -76,7 +76,6 @@ connection.onInitialize((params) => {
};
}),
getLanguageServicePlugins(connection, typescript, collectionConfigs),
{ pullModelDiagnostics: params.initializationOptions?.pullModelDiagnostics },
);
});

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

server.watchFiles([`**/*.{${extensions.join(',')}}`]);
server.fileWatcher.watchFiles([`**/*.{${extensions.join(',')}}`]);
});
7 changes: 5 additions & 2 deletions packages/language-server/src/plugins/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export const create = (ts: typeof import('typescript')): LanguageServicePlugin =
completionProvider: {
triggerCharacters: ['-'],
},
diagnosticProvider: {},
diagnosticProvider: {
interFileDependencies: false,
workspaceDiagnostics: false,
},
codeLensProvider: {},
},
create(context): LanguageServicePluginInstance {
Expand All @@ -51,7 +54,7 @@ export const create = (ts: typeof import('typescript')): LanguageServicePlugin =
items: items,
};
},
provideSemanticDiagnostics(document, token) {
provideDiagnostics(document, token) {
if (token.isCancellationRequested) return [];

const decoded = context.decodeEmbeddedDocumentUri(URI.parse(document.uri));
Expand Down
7 changes: 2 additions & 5 deletions packages/language-server/src/plugins/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const create = (ts: typeof import('typescript')): LanguageServicePlugin[]

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

const diagnostics = await typeScriptPlugin.provideSemanticDiagnostics!(
document,
token,
);
const diagnostics = await typeScriptPlugin.provideDiagnostics!(document, token);
if (!diagnostics) return null;

return enhancedProvideSemanticDiagnostics(diagnostics, tsxLineCount);
Expand Down
6 changes: 1 addition & 5 deletions packages/language-server/test/misc/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ describe('Initialize', async () => {
],
},
definitionProvider: true,
diagnosticProvider: {
interFileDependencies: true,
workspaceDiagnostics: false,
},
documentFormattingProvider: true,
documentHighlightProvider: true,
documentLinkProvider: {},
Expand All @@ -87,7 +83,7 @@ describe('Initialize', async () => {
triggerCharacters: ['=', '>', '/'],
},
fileReferencesProvider: true,
fileRenameProvider: true,
fileRenameEditsProvider: true,
},
foldingRangeProvider: true,
hoverProvider: true,
Expand Down
6 changes: 5 additions & 1 deletion packages/language-server/test/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ export async function getLanguageServer(): Promise<LanguageServer> {
'lib',
),
},
pullModelDiagnostics: true,
contentIntellisense: true,
},
{
textDocument: {
definition: {
linkSupport: true,
},
},
workspace: {
// Needed for tests that use didChangeWatchedFiles
didChangeWatchedFiles: {},
Expand Down
4 changes: 2 additions & 2 deletions packages/ts-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"@astrojs/compiler": "^2.10.3",
"@astrojs/yaml2ts": "^0.2.0",
"@jridgewell/sourcemap-codec": "^1.4.15",
"@volar/language-core": "~2.4.0-alpha.15",
"@volar/typescript": "~2.4.0-alpha.15",
"@volar/language-core": "~2.4.0",
"@volar/typescript": "~2.4.0",
"semver": "^7.3.8",
"vscode-languageserver-textdocument": "^1.0.11"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@
"@types/mocha": "^10.0.1",
"@types/node": "^18.17.8",
"@types/vscode": "^1.82.0",
"@volar/language-server": "~2.4.0-alpha.15",
"@volar/vscode": "~2.4.0-alpha.15",
"@volar/language-server": "~2.4.0",
"@volar/vscode": "~2.4.0",
"@vscode/test-electron": "^2.3.2",
"@vscode/vsce": "2.30.0",
"esbuild": "^0.17.19",
Expand Down
2 changes: 1 addition & 1 deletion packages/yaml2ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"yaml": "^2.5.0"
},
"devDependencies": {
"@volar/language-core": "~2.4.0-alpha.15",
"@volar/language-core": "~2.4.0",
"typescript": "^5.5.4"
}
}
Loading

0 comments on commit 28dfebe

Please sign in to comment.