Skip to content

Commit

Permalink
Update astro check to latest version of the language server (#4754)
Browse files Browse the repository at this point in the history
* Update to latest version of the language server

* Add changeset
  • Loading branch information
Princesseuh committed Sep 21, 2022
1 parent a0619f0 commit baae1b3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/sour-steaks-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Update `astro check` to latest version of the language server
3 changes: 2 additions & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
},
"dependencies": {
"@astrojs/compiler": "^0.24.0",
"@astrojs/language-server": "^0.23.0",
"@astrojs/language-server": "^0.26.2",
"@astrojs/markdown-remark": "^1.1.2",
"@astrojs/telemetry": "^1.0.0",
"@astrojs/webapi": "^1.0.0",
Expand Down Expand Up @@ -147,6 +147,7 @@
"strip-ansi": "^7.0.1",
"supports-esm": "^1.0.0",
"tsconfig-resolver": "^3.0.1",
"typescript": "*",
"unist-util-visit": "^4.1.0",
"vfile": "^5.3.2",
"vite": "~3.1.3",
Expand Down
9 changes: 7 additions & 2 deletions packages/astro/src/cli/check/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { AstroSettings } from '../../@types/astro';
import glob from 'fast-glob';
import * as fs from 'fs';
import { bold, dim, red, yellow } from 'kleur/colors';
import { createRequire } from 'module';
import ora from 'ora';
import { fileURLToPath, pathToFileURL } from 'url';
import { printDiagnostic } from './print.js';
Expand All @@ -23,7 +24,11 @@ export async function check(settings: AstroSettings) {

const spinner = ora(` Getting diagnostics for Astro files in ${fileURLToPath(root)}…`).start();

let checker = new AstroCheck(root.toString());
const require = createRequire(import.meta.url);
let checker = new AstroCheck(
root.toString(),
require.resolve('typescript/lib/tsserverlibrary.js', { paths: [root.toString()] })
);
const filesCount = await openAllDocuments(root, [], checker);

let diagnostics = await checker.getDiagnostics();
Expand All @@ -38,7 +43,7 @@ export async function check(settings: AstroSettings) {

diagnostics.forEach((diag) => {
diag.diagnostics.forEach((d) => {
console.log(printDiagnostic(diag.filePath, diag.text, d));
console.log(printDiagnostic(diag.fileUri, diag.text, d));

switch (d.severity) {
case DiagnosticSeverity.Error: {
Expand Down
3 changes: 1 addition & 2 deletions packages/astro/src/cli/check/print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ export function printDiagnostic(filePath: string, text: string, diag: Diagnostic
// Lines and characters are 0-indexed, so we need to add 1 to the offset to get the actual line and character
const realStartLine = diag.range.start.line + 1;
const realStartCharacter = diag.range.start.character + 1;
const normalizedFilePath = fileURLToPath(new URL(filePath, 'file://'));

// IDE friendly path that user can CTRL+Click to open the file at a specific line / character
const IDEFilePath = `${bold(cyan(normalizedFilePath))}:${bold(yellow(realStartLine))}:${bold(
const IDEFilePath = `${bold(cyan(fileURLToPath(filePath)))}:${bold(yellow(realStartLine))}:${bold(
yellow(realStartCharacter)
)}`;
result.push(
Expand Down
24 changes: 12 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit baae1b3

Please sign in to comment.