Code Monkey home page Code Monkey logo

coc-htmldjango's Introduction

coc-htmldjango

django templates (htmldjango) extension for coc.nvim. Provides "formatter", "linter", "completion" and more...

coc-htmldjango-demo

Features

  • Format
  • Lint
    • by djLint (Find common formatting issues) | DEMO
  • Completion
    • Completion of snippets data via completionItemProvider
  • Hover | DEMO
  • CodeAction | DEMO
  • Commands
  • Built-in installer (djLint, DjHTML)

Install

CocInstall:

:CocInstall coc-htmldjango

vim-plug:

Plug 'yaegassy/coc-htmldjango', {'do': 'yarn install --frozen-lockfile'}

Recommended coc-extensions to install together

Tool (linter & formatter) detection

Detection order:

  • htmldjango.djlint.commandPath and htmldjango.djhtml.commandPath settings
  • current python environment (e.g. djlint and djhtml in "venv")
  • builtin djlint and djhtml (Installation commands are also provided)

Configuration options for coc-htmldjango

  • htmldjango.enable: Enable coc-htmldjango extension, default: true
  • htmldjango.completion.enable: Enable snippets completion, default: true
  • htmldjango.completion.exclude: Exclude specific key in snippet completion, default: ["autoescape_paste", "comment_paste", "comment_selection", "for_paste", "forempty_paste", "if_paste", "ifelse_paste", "spaceless_paste", "verbatim_paste", "with_selection", "with_paste", "trans_paste", "blocktrans_paste", "blocktrans_with_paste", "translate_paste", "blocktranslate_paste", "blocktranslate_with_paste"]
  • htmldjango.builtin.pythonPath: Python 3.x path (Absolute path) to be used for built-in install, default: ""
  • htmldjango.formatting.provider: Provider for formatting. Possible options include 'djlint', 'djhtml' and 'none', default: "djlint"
  • htmldjango.djlint.commandPath: The custom path to the djlint (Absolute path), default: ""
  • htmldjango.djlint.enableLint: Enable djLint lint (diagnostics), default: true
  • htmldjango.djlint.lintOnOpen: Lint file on opening, default: true
  • htmldjango.djlint.lintOnChange: Lint file on change, default: true
  • htmldjango.djlint.lintOnSave: Lint file on save, default: true
  • htmldjango.djlint.include: Codes to include (--include), ex: "H014,H017", default: ""
  • htmldjango.djlint.ignore: Codes to ignore (--ignore), ex: "W013,W014", default: ""
  • htmldjango.djlint.ignoreCase: Do not fix case on known html tags (--ignore-case), default: false
  • htmldjango.djlint.ignoreBlocks: Comma list of template blocks to not indent (--ignore-blocks), default: ""
  • htmldjango.djlint.indent: Indent spacing (--indent), default: 4
  • htmldjango.djlint.profile: Enable defaults by template language. ops: html, django, jinja, nunjucks, handlebars, golang and angular, default: ["django"]
  • htmldjango.djlint.useGitIgnore: Use .gitignore file to extend excludes (--use-gitignore), default: false
  • htmldjango.djlint.preserveLeadingSpace: Attempt to preserve leading space on text (--preserve-leading-space), default: false
  • htmldjango.djlint.preserveBlankLines: Attempt to preserve blank lines (--preserve-blank-lines), default: false
  • htmldjango.djlint.formatCss: Also format contents of style tags (--format-css), default: false
  • htmldjango.djlint.formatJs: Also format contents of script tags (--format-js), default: false
  • htmldjango.djlint.addLinterArgs: Additional arguments passed to djlint linter, example: ["--max-line-length", "250", "--max-attribute-length", "80"], default: []
  • htmldjango.djlint.addFormatterArgs: Additional arguments passed to djlint formatter, example: ["--max-line-length", "250", "--max-attribute-length", "80"], default: []
  • htmldjango.djhtml.commandPath: The custom path to the djhtml (Absolute path), default: ""
  • htmldjango.djhtml.tabWidth: Set tabwidth (--tabwidth), default: 4

Commands

  • htmldjango.showOutput: Show htmldjango output channel
  • htmldjango.builtin.installTools: Install htmldjango related tools
  • htmldjango.djlint.format: Run djLint format
  • htmldjango.djhtml.format: Run DjHTML format
  • htmldjango.showReferences: Show Variables Block ({{ ... }}) or TemplateTags Block ({% ... %}) location information for the current file

Code Actions

Example key mapping (Code Action related):

nmap <silent> ga <Plug>(coc-codeaction-line)

Actions:

  • If htmldjango.formatting.provider is djlint or If htmldjango.djlint.enableLint is true
    • Add <!-- djlint:off --> for this line
    • Add <!-- djlint:on --> for this line
  • If htmldjango.formatting.provider is djhtml
    • Add {# fmt:off #} for this line
    • Add {# fmt:on #} for this line

Bult-in install (djLint, DjHTML)

coc-htmldjango allows you to create an extension-only "venv" and install "djlint" and "djhtml".

:CocCommand htmldjango.builtin.installTools

Thanks

License

MIT


This extension is built with create-coc-extension

coc-htmldjango's People

Contributors

dependabot[bot] avatar yaegassy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

daysuwaa

coc-htmldjango's Issues

Timeouts on larger files

Hey, not a bug in this repository most likely but looking for a solution. Djlint is very slow on larger files and CoC seems to have a 500ms timeout. How can I disable auto formatting on save. And enable formatting by calling CocAction that does not have a timeout.

au BufWrite *.html call CocAction('format')

And setting the provider to none:

"htmldjango.formatting.provider": "none",

Disables autoformatting on save that has the timeout, but also removes the formatting provider which makes the format action illegible. Is there some other flag to disable formatting? Or any other solution?

Thanks!

Use settings from pyproject.toml

Hi,

I add these options to use settings from pyproject.toml.

  "htmldjango.djlint.addLinterArgs": [
    "--configuration=pyproject.toml"
  ],
  "htmldjango.djlint.addFormatterArgs": [
    "--configuration=pyproject.toml"
  ],

But I think coc-htmldjango settings for indentation overwrites it.

Settings from django-cookiecutter

# ==== djLint ====
[tool.djlint]
blank_line_after_tag = "load,extends"
close_void_tags = true
format_css = true
format_js = true
# TODO: remove T002 when fixed https://github.com/Riverside-Healthcare/djLint/issues/687
ignore = "H006,H030,H031,T002"
include = "H017,H035"
indent = 2
max_line_length = 119
profile = "django"

[tool.djlint.css]
indent_size = 2

[tool.djlint.js]
indent_size = 2

djlint . --reformat and coc-htmldjango linting has different output.

I would like coc-htmldjango to pick up project settings and not have IDE settings as defaults.

Any suggesitons? Thanks!

djlint tabWidth

Hi, would it be possible to be able to set the tabWidth for the djlint format command? Thanks.

Wrong file type detection while file starts with comments larger than 5 lines.

Hello @yaegassy,

Thanks a lot for that wonderful plugin.

I am not sure if this extension is directly interacting with the file type, but I noticed that detection is not working properly when the template is starting with a comment that is longer than 5 lines.

Something like:

{#
Comment longer than 5 lines.
Comment longer than 5 lines.
Comment longer than 5 lines.
Comment longer than 5 lines.
Comment longer than 5 lines.
Comment longer than 5 lines.
#}

{% extends "parent/something.html" %}
{% block page_title %}{{ test }} - Grid - {{ appbuilder.app_name }}{% endblock %}
{% from 'appbuilder/loading_dots.html' import loading_dots %}

{% block tail_js %}
{{ super() }}
<script>
  const something = {{data| tojson }};
</script>
<script src="{{ url_for_asset('something.js') }}"></script>
{% endblock % }

Removing one line in the comment will result in a correct file type detection -> htmldjango, while this stays for me as html.

Any idea on how to fix this ?

Best regards,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.