Visitar URL original
Update language-tools (#17578) · withastro/astro@7cc0b00 · GitHub
Skip to content

Commit 7cc0b00

Browse files
Update language-tools (#17578)
Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
1 parent 5c20957 commit 7cc0b00

16 files changed

Lines changed: 198 additions & 138 deletions

File tree

‎.changeset/yummy-buckets-occur.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/language-server': patch
3+
---
4+
5+
Fixes a case where rich content diagnostics and snippet edits would not work

‎packages/language-tools/astro-check/package.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434
"@astrojs/language-server": "^2.16.7",
3535
"chokidar": "^4.0.3",
3636
"kleur": "^4.1.5",
37-
"yargs": "^18.0.0"
37+
"yargs": "^18.1.0"
3838
},
3939
"devDependencies": {
4040
"@types/node": "^22.10.6",
4141
"@types/yargs": "^17.0.35",
4242
"astro-scripts": "workspace:*",
43-
"tinyglobby": "^0.2.16",
44-
"tsx": "^4.22.0"
43+
"tinyglobby": "^0.2.17",
44+
"tsx": "^4.23.13"
4545
},
4646
"peerDependencies": {
4747
"typescript": "^5.0.0 || ^6.0.0"

‎packages/language-tools/language-server/package.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"@volar/language-server": "~2.4.28",
3434
"@volar/language-service": "~2.4.28",
3535
"muggle-string": "^0.4.1",
36-
"tinyglobby": "^0.2.16",
36+
"tinyglobby": "^0.2.17",
3737
"volar-service-css": "0.0.71",
3838
"volar-service-emmet": "0.0.71",
3939
"volar-service-html": "0.0.71",
@@ -49,9 +49,9 @@
4949
"@volar/test-utils": "~2.4.28",
5050
"@volar/typescript": "~2.4.28",
5151
"astro-scripts": "workspace:*",
52-
"tsx": "^4.22.0",
52+
"tsx": "^4.23.13",
5353
"typescript": "^6.0.3",
54-
"vscode-languageserver-protocol": "^3.17.5",
54+
"vscode-languageserver-protocol": "^3.18.3",
5555
"vscode-languageserver-textdocument": "^1.0.14"
5656
},
5757
"peerDependencies": {

‎packages/language-tools/language-server/src/plugins/typescript/codeActions.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Range, TextDocumentEdit } from '@volar/language-server';
1+
import { type Range, TextDocumentEdit, TextEdit } from '@volar/language-server';
22
import type { CodeAction, LanguageServiceContext } from '@volar/language-service';
33
import { URI } from 'vscode-uri';
44
import { AstroVirtualCode } from '../../core/index.js';
@@ -42,7 +42,10 @@ function mapCodeAction(codeAction: CodeAction, context: LanguageServiceContext)
4242
}
4343
if (hadEdits && change.edits.length === 0) return [];
4444

45-
change.edits = change.edits.map((edit) => mapEdit(edit, root, virtualCode.languageId));
45+
// Snippet edits have no `newText` to rewrite, so they're passed through untouched
46+
change.edits = change.edits.map((edit) =>
47+
TextEdit.is(edit) ? mapEdit(edit, root, virtualCode.languageId) : edit,
48+
);
4649
}
4750

4851
return [change];

‎packages/language-tools/language-server/src/plugins/typescript/diagnostics.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export function enhancedProvideSemanticDiagnostics(
3434

3535
// General enhancements that apply to all files
3636
function generalEnhancements(diagnostic: Diagnostic) {
37+
// Our enhancements match on the text of the message, which TypeScript always emits as a plain string
38+
if (typeof diagnostic.message !== 'string') return diagnostic;
39+
3740
if (
3841
diagnostic.code === DiagnosticCodes.CANNOT_FIND_MODULE &&
3942
diagnostic.message.includes('astro:content')
@@ -52,6 +55,9 @@ function generalEnhancements(diagnostic: Diagnostic) {
5255
* or a difference with JSX needing a different error message
5356
*/
5457
function astroEnhancements(diagnostic: Diagnostic): Diagnostic {
58+
// Our enhancements match on the text of the message, which TypeScript always emits as a plain string
59+
if (typeof diagnostic.message !== 'string') return diagnostic;
60+
5561
// When the language integrations are not installed, the content of the imported snapshot is empty
5662
// As such, it triggers the "is not a module error", which we can enhance with a more helpful message for the related framework
5763
if (diagnostic.code === DiagnosticCodes.IS_NOT_A_MODULE) {

‎packages/language-tools/language-server/src/plugins/yaml.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ export const create = (collectionConfig: CollectionConfig): LanguageServicePlugi
115115
diagnostic.severity = DiagnosticSeverity.Error;
116116

117117
// Map missing properties to the entire frontmatter
118-
if (diagnostic.message.startsWith('Missing property')) {
118+
if (
119+
typeof diagnostic.message === 'string' &&
120+
diagnostic.message.startsWith('Missing property')
121+
) {
119122
diagnostic.range = Range.create(
120123
{ line: 0, character: 0 },
121124
document.positionAt(document.getText().length),

‎packages/language-tools/language-server/test/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"svelte": "^5.55.3"
1010
},
1111
"devDependencies": {
12-
"tinyglobby": "^0.2.16"
12+
"tinyglobby": "^0.2.17"
1313
}
1414
}

‎packages/language-tools/language-server/test/server.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'node:path';
33
import { fileURLToPath } from 'node:url';
44
import type { LanguageServerHandle } from '@volar/test-utils';
55
import { startLanguageServer } from '@volar/test-utils';
6-
import * as protocol from 'vscode-languageserver-protocol/node.js';
6+
import * as protocol from 'vscode-languageserver-protocol/node';
77
import type { TextDocument } from 'vscode-languageserver-textdocument';
88
import { URI } from 'vscode-uri';
99
import { fixtureDir } from './test-utils.ts';

‎packages/language-tools/language-server/test/typescript/code-actions.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import assert from 'node:assert';
22
import { before, describe, it } from 'node:test';
3-
import { type CodeAction, type FullDocumentDiagnosticReport, Range } from '@volar/language-server';
3+
// Imported from the node entry so the types line up with the `@volar/test-utils` handle
4+
import {
5+
type CodeAction,
6+
type FullDocumentDiagnosticReport,
7+
Range,
8+
} from '@volar/language-server/node.js';
49
import { getLanguageServer, type LanguageServer } from '../server.ts';
510

611
describe('TypeScript - Code Actions', () => {

‎packages/language-tools/language-server/test/typescript/diagnostics.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import assert from 'node:assert';
22
import * as path from 'node:path';
33
import { before, describe, it } from 'node:test';
4-
import type { FullDocumentDiagnosticReport } from '@volar/language-server';
5-
import { type Diagnostic, DiagnosticSeverity, Range } from '@volar/language-server';
4+
// Imported from the node entry so the types line up with the `@volar/test-utils` handle
5+
import type { FullDocumentDiagnosticReport } from '@volar/language-server/node.js';
6+
import { type Diagnostic, DiagnosticSeverity, Range } from '@volar/language-server/node.js';
67
import { getLanguageServer, type LanguageServer } from '../server.ts';
78
import { fixtureDir } from '../test-utils.ts';
89

0 commit comments

Comments
 (0)