Skip to content
Draft
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
19 changes: 18 additions & 1 deletion packages/language-tools/ts-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,27 @@ import { getFrontmatterLanguagePlugin } from './frontmatter.js';
import { getLanguagePlugin } from './language.js';

export = createLanguageServicePlugin((ts, info) => {
const currentDir = info.project.getCurrentDirectory();

// Check if this is an Astro project by looking for astro.config.* file
if (ts.sys.readDirectory) {
const hasAstroConfig =
ts.sys.readDirectory(
currentDir,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest checking that this work inside monorepos!

['js', 'mjs', 'cjs', 'ts', 'mts', 'cts'],
undefined,
['astro.config.*'],
1,
).length > 0;

if (!hasAstroConfig) {
return { languagePlugins: [] };
}
}

let collectionConfig = undefined;

try {
const currentDir = info.project.getCurrentDirectory();
const fileContent = ts.sys.readFile(currentDir + '/.astro/collections/collections.json');
if (fileContent) {
collectionConfig = {
Expand Down
Loading