diff --git a/.changeset/hungry-nails-pull.md b/.changeset/hungry-nails-pull.md new file mode 100644 index 00000000..237cc525 --- /dev/null +++ b/.changeset/hungry-nails-pull.md @@ -0,0 +1,8 @@ +--- +"@astrojs/language-server": minor +"@astrojs/ts-plugin": minor +--- + +Updates where to look for JSON Schemas for content intellisense. + +In 5.0, schemas are moved from `.astro/` to `.astro/astro`. Checks are now made against both directories. diff --git a/packages/language-server/src/nodeServer.ts b/packages/language-server/src/nodeServer.ts index 477ce216..6fe9dcae 100644 --- a/packages/language-server/src/nodeServer.ts +++ b/packages/language-server/src/nodeServer.ts @@ -42,9 +42,13 @@ connection.onInitialize((params) => { try { const folderUri = URI.parse(folder.uri); let config = server.fileSystem.readFile( - Utils.joinPath(folderUri, '.astro/collections/collections.json'), + Utils.joinPath(folderUri, '.astro/astro/collections/collections.json'), ); - + if (!config) { + config = server.fileSystem.readFile( + Utils.joinPath(folderUri, '.astro/collections/collections.json'), + ); + } if (!config) { return []; } diff --git a/packages/ts-plugin/src/index.ts b/packages/ts-plugin/src/index.ts index 3b753f6b..bec9e35f 100644 --- a/packages/ts-plugin/src/index.ts +++ b/packages/ts-plugin/src/index.ts @@ -4,27 +4,40 @@ import type { CollectionConfig } from './frontmatter.js'; import { getFrontmatterLanguagePlugin } from './frontmatter.js'; import { getLanguagePlugin } from './language.js'; -export = createLanguageServicePlugin((ts, info) => { - let collectionConfig = undefined; - +function getCollectionConfig( + readFile: (path: string) => string | undefined, +): CollectionConfig['config'] | undefined { try { - const currentDir = info.project.getCurrentDirectory(); - const fileContent = ts.sys.readFile(currentDir + '/.astro/collections/collections.json'); + let fileContent = readFile('/.astro/astro/collections/collections.json'); + if (fileContent) { + return JSON.parse(fileContent); + } + fileContent = readFile('/.astro/collections/collections.json'); if (fileContent) { - collectionConfig = { - folder: currentDir, - config: JSON.parse(fileContent) as CollectionConfig['config'], - }; + return JSON.parse(fileContent); } } catch (err) { // If the file doesn't exist, we don't really care, but if it's something else, we want to know if (err && (err as any).code !== 'ENOENT') console.error(err); } +} + +export = createLanguageServicePlugin((ts, info) => { + const currentDir = info.project.getCurrentDirectory(); + + const collectionConfig = getCollectionConfig((path) => ts.sys.readFile(currentDir + path)); let languagePlugins: LanguagePlugin[] = [getLanguagePlugin()]; if (collectionConfig) { - languagePlugins.push(getFrontmatterLanguagePlugin([collectionConfig])); + languagePlugins.push( + getFrontmatterLanguagePlugin([ + { + folder: currentDir, + config: collectionConfig, + }, + ]), + ); } return {