Skip to content
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

We should have HTML attribute snippet completion of the ="" #345

Closed
stijns96 opened this issue Apr 12, 2024 · 4 comments · Fixed by #520
Closed

We should have HTML attribute snippet completion of the ="" #345

stijns96 opened this issue Apr 12, 2024 · 4 comments · Fixed by #520
Assignees
Labels
Bug Something isn't working open for contributions theme bugs that won't be prioritized in the near future

Comments

@stijns96
Copy link
Contributor

stijns96 commented Apr 12, 2024

Describe the bug
When I type clas, the editor will suggest me to auto complete class. Normally it's smart enough to add =""`` as well where your cursor will be placed within "". This is not the case. It only autocompletes the word, but without =""`.

Source

<div class></div>

Expected behaviour
When I hit tab when a suggestion pops up, I expect that it will be completed with ="" at the end with my cursor inside "".

Actual behaviour
When I hit tab when a suggestion pops up, it only autocompletes the word.

Debugging information

  • OS Mac
  • OS 14.2.1 (23C71)
  • Theme Check Version v2.3.0 (extension)

Additional context
I created my own extension ones which is working correctly. At that time, HTML autocompletion was not working yet with the Shopify extension. Since it is kind of working now, I got the suggestions twice.

Might be worth to checkout vscode-html-languageservice as well.

Handy links

Good to know
vscode-html-languageservice is checking for tags that doesn't have the valueSet set to 'v'. If it has 'v', the attribute doesn't support any value.

@stijns96
Copy link
Contributor Author

stijns96 commented Apr 12, 2024

My apologies. I now also see this issue. I'll leave this one open, so you can read a little bit of my additional context as well.

@charlespwd
Copy link
Contributor

charlespwd commented Apr 12, 2024

It's all good I prefer the context in this one :) I'd love to get around doing that one.

We support snippet completion in the codemirror-language-client now (had to do it for JSON completion in the Shopify admin), so there's nothing stopping us from adding snippet completions in our HtmlAttributeCompletionProvider

Things to look at for is making sure we do re-add them if the equal sign is already there.

From the spec, what we need to add is this:

  • When the editor supports it, a snippet insertTextFormat in the completionItem
  • an insertText that includes the =, " and $1. Something like${name}="$1"$0.
  • a textEdit that replaces the entire attribute
  • An if statement that turns all that stuff off if the stars are not aligned (e.g. there might already by an =, etc.)

Resources

@charlespwd charlespwd changed the title ="" not automatically added with HTML attributes We should have HTML attribute snippet completion of the ="" Apr 12, 2024
@charlespwd
Copy link
Contributor

(Updated above comment with more breadcrumbs in case it isn't me that implements it :))

@stijns96
Copy link
Contributor Author

stijns96 commented May 2, 2024

Hi @charlespwd,

I try to contribute here and figured out what to do. The only thing is that debugging is quite hard... I added the following (WIP), but this should do the easy trick.

HtmlAttributeCompletionProvider

function toCompletionItem(tag: Attribute): CompletionItem {
  return {
    label: tag.name,
    kind: CompletionItemKind.Value,
    insertText: tag.valueSet !== 'v' ? `${tag.name}="$1"` : tag.name,
    documentation: {
      kind: 'markdown',
      value: renderHtmlEntry(tag),
    },
  };
}

I did a format -> build -> test and have it running with pressing F5. I create a simple liquid file and type <button t></button>. In my debugger I get my consoles, but somehow the server is erroring.

Any idea why? When I remove my edits, it works fine.

image image

@mgmanzella mgmanzella added Bug Something isn't working open for contributions theme bugs that won't be prioritized in the near future labels Jun 18, 2024
@aswamy aswamy self-assigned this Sep 30, 2024
@aswamy aswamy linked a pull request Oct 7, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working open for contributions theme bugs that won't be prioritized in the near future
Projects
None yet
4 participants