Closed JeanMertz closed 4 years ago
Seems we need upgrade dependencies, PR welcome.
Seems we need upgrade dependencies
Are you sure about that? From what I can tell, the commit that added this support was already available in 3.0.0, and coc-html is using 3.0.2 (see also the js-beautify 1.10 release notes).
Those release notes also mention:
All languages are off by default in Javascript and on by default in HTML
So I'm not sure why it isn't enabled by default in the case of coc-html.
Or did you mean some other dependency that needs to be upgraded?
I don't know how to enable it, you can help to look at the source code.
Hi guys
I found the solution
just add "django" to to "html-filetypes" in coc-settings.json
ex: "html.filetypes": [ "html", "handlebars", "django" ]
Doesn't work for me. According to https://code.djangoproject.com/wiki/UsingVimWithDjango#Syntaxfortemplates :
Vim 7.1 or newer includes support for "htmldjango" documents out of the box.
All my html files are auto-set to ft=htmldjango
coc-settings.json
{
"html.enable": true,
"html.filetypes": [
"html",
"handlebars",
"django",
"htmldjango"
],
"html.format.enable": true
}
Tried with django only (and changing the file filetype=django) and htmldjango only, didn't change anything.
When running :call CocAction("format")
, then check logs with :CocOpenLog
, I see
2020-01-31T10:42:22.083 ERROR (pid:1853450) [languages] - Format provider not found for current document error
Not seeing any html format provider option available from coc-settings though:
After exporting NVIM_COC_LOG_LEVEL=debug
and trying again, I'm getting these logs:
I couldn't figure out how to get languages to create a service source html
Checkout :h g:coc_filetype_map
Thanks! Still haven't figured out something satisfying.
~/.vimrc
let g:coc_filetype_map = {
\ 'htmldjango': 'html',
\ }
coc-settings.js
"html.enable": true,
"html.format.enable": true,
"html.filetypes": [
"html",
"htmldjango"
],
Test code:
When I run ':Format' (command! -nargs=0 Format :call CocAction('format')
), it says "Formatted by prettier" and the result is ugly (django template tags completely messed up)
If I add "prettier.formatterPriority": -1
in coc-settings, then try :Format again on the test code, I get
Looks like all the django stuff is just ignored and leaved as is.
What I wish the formatter to do is either one of the 2 following versions:
Any idea how to get there?
Note that I tried setting
let g:coc_filetype_map = {
\ 'htmldjango': 'django',
\ }
with coc-settings.js
"html.enable": true,
"html.format.enable": true,
"html.filetypes": [
"django"
],
And :Format
won't do anything. Actually, the coc-html server won't even start!
To verify that the bug is coc-html specific, I applied the same config to coc-tailwindcss
"tailwindCSS.htmlLanguages": [
"django"
],
After opening my file nvim file.html
, I see:
$ ps auxw|grep node-ipc
dori 1006799 60.0 0.3 941200 115196 ? Sl 11:43 0:01 /usr/bin/node /home/dori/.config/coc/extensions/node_modules/coc-tailwindcss/lsp/tailwindcss-language-server/dist/index.js --node-ipc --clientProcessId=1006784
dori 1006921 0.0 0.0 7628 2432 pts/4 S+ 11:43 0:00 grep --color=auto node-ipc
tailwindcss server is started, but not the html one. @chemzqm any idea why?
What I understand is that I should map htmldjango to django for coc-html to apply django formatting to my file, but coc-html will only work with filetype html at the moment. And it lets prettier take over if coc-prettier is installed without any custom global or local settings.
@chemzqm another issue: the filetype map conflicts with coc-snippets.
In coc-snippets, "django" filetype is associated to python files (models & co), while "htmldjango" filetype is associated to templates.
I think this makes sense.
Instead of remapping htmldjango to django for coc-html, it would make more sense to rename all occurences of "django" to "htmldjango" in coc-html's source code.
$ perl -p -i -e 's/django/htmldjango/g' ~/.config/coc/extensions/node_modules/coc-html/lib/server.js
Yes, PR welcome
@chemzqm I would, but as said above, I can't even get coc-html ipc process to start
tailwindcss server is started, but not the html one. @chemzqm any idea why?
I can only get coc-html's client process started when the filetype is html, and I need to uninstall coc-prettier first.
Thanks for updating the plugin. Unfortunately, the formatting is still quite unsatisfactory:
test:
<span class="flex items-center mt-3">
{%for _ in '12345'|make_list %}
{% if forloop.counter <= page.rating %}
<span class="mr-3 text-{{ current_category.color }}-400">
{% include 'svg/rating-star.svg' %}
</span>
{% else %}
<span class="mr-3">
{% include 'svg/rating-star-empty.svg' %}
</span>
{% endif %}
{% endfor %}
</span>
coc-html :Format
<span class="flex items-center mt-3">
{%for _ in '12345'|make_list %}
{% if forloop.counter <= page.rating %}
<span class="mr-3 text-{{ current_category.color }}-400">
{% include 'svg/rating-star.svg' %}
</span>
{% else %}
<span class="mr-3">
{% include 'svg/rating-star-empty.svg' %}
</span>
{% endif %}
{% endfor %}
</span>
vim visual selection and =
<span class="flex items-center mt-3">
{%for _ in '12345'|make_list %}
{% if forloop.counter <= page.rating %}
<span class="mr-3 text-{{ current_category.color }}-400">
{% include 'svg/rating-star.svg' %}
</span>
{% else %}
<span class="mr-3">
{% include 'svg/rating-star-empty.svg' %}
</span>
{% endif %}
{% endfor %}
</span>
= is much better already.
Also, nothing will auto-add spaces in tags {%for
=> {% for
.
I looked around, but neither js-beautify nor prettier have support for django template formatting at the moment, it seems.
Same as VSCode, it's formatted by https://github.com/Microsoft/vscode-html-languageservice, you can send feature request there
Could someone integrate this library https://pypi.org/project/djhtml/1.2.0/ with this plugin? Reopen maybe ?
Django templates syntax support is still not present, can it be changed?
Django templates syntax support is still not present, can it be changed?
You should use vim syntax plugin for that.
Could someone integrate this library https://pypi.org/project/djhtml/1.2.0/ with this plugin? Reopen maybe ?
It's python package, you can use vim plugin that make use of it or simply write a command yourself.
Provide reference information for carers: try coc-htmldjango
coc-html (via
vscode-html-languageservice
) supports Handlebars templates, e.g. this formats as expected:But when using Django-like templating by replacing
{{
and}}
with{%
and%}
, the formatter can't handle that:However, looking at the
vscode-html-languageservice
source code it appears that Django templating is supported as well.Is there a way to make this work with coc-html?