-
-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Content Collections Intellisense #915
Conversation
🦋 Changeset detectedLatest commit: afda8cb The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -22,7 +22,7 @@ | |||
"@changesets/cli": "^2.26.1", | |||
"prettier": "^3.2.5", | |||
"turbo": "1.10.2", | |||
"typescript": "^5.2.2", | |||
"typescript": "^5.5.4", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to the PR, but I was getting a wonky TS error somewhere and updating TS fixed it.
// The vast majority of clients support workspaceFolders, but notably our tests currently don't | ||
// Ref: https://github.com/volarjs/volar.js/issues/229 | ||
const folders = | ||
params.workspaceFolders ?? (params.rootUri ? [{ uri: params.rootUri }] : []) ?? []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This brought me back to 2 years ago when you actually needed to handle rootURI
. Good times (no)
} | ||
|
||
if (hasChanges) { | ||
// TODO: Figure out how to refresh the diagnostics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't figure out a way to do this from a Volar service, will have to ask Johnson. It's not too impactful, as soon as you trigger any actions that refresh the diagnostics (open the file, type anything etc) it refreshes normally.
|
||
return { | ||
...yamlPluginInstance, | ||
// Disable codelenses, we'll provide our own |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not included in this PR, but disabling the built-in code lenses is still valuable, they're irrelevant for Astro users.
--- | ||
import { getEntryBySlug } from 'astro:content'; | ||
getEntryBySlug; | ||
--- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test no longer work since we now generate types in the tests. That's okay because the feature being tested here is still tested, just not.. double tested
@@ -2,6 +2,9 @@ | |||
"name": "astro-language-server-test", | |||
"private": true, | |||
"devDependencies": { | |||
"astro": "^4.1.0" | |||
"astro": "0.0.0-content-collections-intellisense-20240808223933" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To replace with the actual version once it's out.
if (collectionConfig) { | ||
languagePlugins.push(getFrontmatterLanguagePlugin([collectionConfig])); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately in TS plugins getting any kind of config (apart from tsconfig.json
) is really annoying. As such, the feature is always enabled there when it finds a config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I more or less / maybe / a little bit grasp what's going on, but otherwise the code generally looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left questions. Few things:
- there's a bunch of repeated code, can that be shared?
- there are few magic numbers that don't have any comment associated that explain them
- I've seen many bang operators (e.g.
yamlPluginInstance.provide!['yaml/languageService']
) used. It would be great to add a// SAFETY
comment that explains why they are safe to use
packages/yaml2ts/src/yaml2ts.ts
Outdated
const valueKey = JSON.stringify(item.key.toJS(frontmatterContent)); | ||
|
||
frontmatterMappings.push({ | ||
generatedOffsets: [fullResult.length + objectContent.length], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I prefer to see fullResult.length
being passed as parameter, so the function stays pure.
} | ||
|
||
if (isSeq(item)) { | ||
mapSeq(item); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I wish we could avoid recursion... 😅
const SUPPORTED_FRONTMATTER_EXTENSIONS = { md: 'markdown', mdx: 'mdx', mdoc: 'mdoc' }; | ||
const SUPPORTED_FRONTMATTER_EXTENSIONS_KEYS = Object.keys(SUPPORTED_FRONTMATTER_EXTENSIONS); | ||
const SUPPORTED_FRONTMATTER_EXTENSIONS_VALUES = Object.values(SUPPORTED_FRONTMATTER_EXTENSIONS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is repeated code, any chance to make this shared?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit wonky to make shared because it's in different packages with no link between each others apart from one and it doesn't really belong in the YAML 2 TS package since it doesn't deal with the supported languages, but I guess it could be there
Changes
Adds support for intellisense inside Markdown, MDX and Markdoc. Everything expected is supported, diagnostics, completions, hover, go to definition / references (both on the .md/.mdx/.mdoc side and the .ts side), etc.
Currently, this is behind a
astro.content-intellisense
flag as the feature in core is also experimental.Testing
Added tests
Docs
Will be documented on the Astro part of things mostly