-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add theme block type completion in {% schema %}
#632
base: main
Are you sure you want to change the base?
Conversation
The `BlockTypeCompletionProvider` offers value completions of the `blocks.[].type` property inside section and theme block `{% schema %}` tags. ```liquid {% schema %} { "blocks": [ { "type": "█" }, ] } {% endschema %} ``` Fixes #627
13ff1da
to
b041721
Compare
export function isPresetBlockPath(path: JSONPath) { | ||
return path.at(0) === 'presets'; | ||
} |
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.
Unused but might want to refactor and use for #628
// - presets.[](recursive .blocks.[].type) | ||
// - presets.[](recursive .blocks.{}.type) | ||
const topLevel = path.at(0); | ||
if (topLevel !== 'blocks' && topLevel !== 'presets') return false; | ||
if (path.length < 4) return false; // minimum path length | ||
const [shouldBeBlocks, _idOrIndex, shouldBeType] = path.slice(-3); | ||
return shouldBeBlocks === 'blocks' && shouldBeType === 'type'; |
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.
Same that was something I used before I planned to split #628 to a different provider
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.
🎩 went well, just a few small things
@@ -166,7 +166,11 @@ export class DocumentManager { | |||
|
|||
/** Lazy and only computed once per file version */ | |||
getSchema: memo(async () => { | |||
if (!this.getModeForUri || !this.isValidSchema) return undefined; | |||
// For when you don't care about validation... (e.g. tests) |
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.
Maybe we could only return this is a test env?
label: `"${name}"`, | ||
insertText: `"${name}"`, |
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.
label: `"${name}"`, | |
insertText: `"${name}"`, | |
label: name, | |
insertText: name, |
My eyes might be deceiving me but I think we can just do this?
} from 'vscode-languageserver-protocol'; | ||
import { DocumentManager } from '../../documents'; | ||
|
||
export function getParams( |
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.
Are these really "params"? Maybe I need to rethink what I think params are in theme-tools context?
Edit: ah, I see these were just copy/pasted from an existing file anyways
expect(completions.items.map((item) => item.label)).to.include.members([ | ||
'"@app"', | ||
'"@theme"', | ||
...blockNames.map((x) => `"${x}"`), |
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.
Interpolation overload perhaps?
...blockNames.map((x) => `"${x}"`), | |
...blockNames, |
expect(completions.items.map((item) => item.label)).not.to.include.members([ | ||
...blockNames.map((x) => `"${x}"`), | ||
]); |
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.
expect(completions.items.map((item) => item.label)).not.to.include.members([ | |
...blockNames.map((x) => `"${x}"`), | |
]); | |
expect(completions.items.map((item) => item.label)).not.to.include.members(blockNames); |
What are you adding in this PR?
The
BlockTypeCompletionProvider
offers value completions of theblocks.[].type
property inside section and theme block{% schema %}
tags.Fixes #627
block-type-completion.mp4
What's next? Any followup issues?
#545
Before you deploy
changeset