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
1 change: 1 addition & 0 deletions .changeset/kind-pears-behave.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
'astro': major
'@astrojs/language-server': patch
---

Removes `Astro.glob()`
Expand Down
2 changes: 1 addition & 1 deletion packages/language-tools/language-server/src/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class AstroCheck {
getSvelteLanguagePlugin(),
getVueLanguagePlugin(),
];
const services = [...createTypeScriptServices(this.ts), createAstroService(this.ts)];
const services = [...createTypeScriptServices(this.ts), createAstroService()];

if (tsconfigPath) {
const includeProjectReference = false; // #920
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function getLanguageServicePlugins(
}),
createTypeScriptTwoSlashService(ts),
createTypescriptAddonsService(),
createAstroService(ts),
createAstroService(),
getPrettierService(),
createYAMLService(collectionConfig),
];
Expand Down
64 changes: 1 addition & 63 deletions packages/language-tools/language-server/src/plugins/astro.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { dirname } from 'node:path';
import type { DiagnosticMessage } from '@astrojs/compiler/types';
import type {
CodeLens,
CompletionItem,
Diagnostic,
LanguageServicePlugin,
Expand All @@ -14,14 +12,11 @@ import {
Range,
TextEdit,
} from '@volar/language-server';
import fg from 'fast-glob';
import type { Provide } from 'volar-service-typescript';
import type { TextDocument } from 'vscode-html-languageservice';
import { URI } from 'vscode-uri';
import { AstroVirtualCode } from '../core/index.js';
import { isJSDocument } from './utils.js';

export const create = (ts: typeof import('typescript')): LanguageServicePlugin => {
export const create = (): LanguageServicePlugin => {
return {
capabilities: {
completionProvider: {
Expand All @@ -31,7 +26,6 @@ export const create = (ts: typeof import('typescript')): LanguageServicePlugin =
interFileDependencies: false,
workspaceDiagnostics: false,
},
codeLensProvider: {},
},
create(context): LanguageServicePluginInstance {
return {
Expand Down Expand Up @@ -76,67 +70,11 @@ export const create = (ts: typeof import('typescript')): LanguageServicePlugin =
};
}
},
provideCodeLenses(document, token) {
if (token.isCancellationRequested) return;
if (!isJSDocument(document.languageId)) return;

if (!context.project.typescript) return;

const { uriConverter } = context.project.typescript;
const languageService = context.inject<Provide, 'typescript/languageService'>(
'typescript/languageService',
);
if (!languageService) return;

const tsProgram = languageService.getProgram();
if (!tsProgram) return;

const decoded = context.decodeEmbeddedDocumentUri(URI.parse(document.uri));
if (!decoded) return;

const globcodeLens: CodeLens[] = [];
const sourceFile = tsProgram.getSourceFile(decoded[0].fsPath)!;

function walk() {
return ts.forEachChild(sourceFile, function cb(node): void {
if (ts.isCallExpression(node) && node.expression.getText() === 'Astro.glob') {
const globArgument = node.arguments.at(0);

if (globArgument && decoded) {
globcodeLens.push(
getGlobResultAsCodeLens(
globArgument.getText().slice(1, -1),
dirname(uriConverter.asFileName(decoded[0])),
document.positionAt(node.arguments.pos),
),
);
}
}
return ts.forEachChild(node, cb);
});
}

walk();

return globcodeLens;
},
};
},
};
};

function getGlobResultAsCodeLens(globText: string, dir: string, position: Position) {
const globResult = fg.sync(globText, {
cwd: dir,
onlyFiles: true,
});

return {
range: Range.create(position, position),
command: { title: `Matches ${globResult.length} files`, command: '' },
};
}

function getFrontmatterCompletion(
file: AstroVirtualCode,
document: TextDocument,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ describe('Initialize', async () => {
],
resolveProvider: true,
},
codeLensProvider: {},
colorProvider: true,
completionProvider: {
resolveProvider: true,
Expand Down
Loading