spotify / dockerfile-mode

An emacs mode for handling Dockerfiles
Apache License 2.0
536 stars 79 forks source link

LSP interfere with indentation function #89

Open sfavazza opened 1 week ago

sfavazza commented 1 week ago

I use spacemacs and in my configuration, both LSP-mode and Dockerfile mode are enabled when editing an image description file.

Issue: when indenting a line (no matter the content), the line get unconditionally indented by dockerfile-indent-offset spaces. Checking the dockerfile-indent-line-function function I discovered that the function does not recognize the faces anymore as they are overwritten by lsp-semantic-tokens-mode.

Proposed solution: as I could not find much info on how to detect whether a word is a keyword or a part of a comment (syntax-pps does not recognize the begging of a comment). I would think of the following possibility:

1 - check whether lsp-semantic-tokens-mode is active, temparirily disable it, check which kind of line are we in, re-enable lsp-semantic-tokens-mode and perform the indentation.

2 - leveraging the fact that the lsp-semantinc-tokens-mode assigns meaningfully names faces, we might check that a particular string is included in the names of the retrieved thing-at-point faces (e.g. lsp-face-semhl-keyword <-> font-lock-keyword-face) and apply indentation accordingly

3 - detect only comments delimiters and keyword via reg-exp and indent accordingly (trowing out the text face all together)

4 - ignore any mentioned solution and direct this issue to the spacemacs community (I guess this will require and advice-add approach)

Happy to contribute if help is needed.

drewcsillag commented 5 days ago

I honestly don't know enough about LSP-mode to know the right answer here. But contributions are welcome!