haskell / haskell-mode

Emacs mode for Haskell
http://haskell.github.io/haskell-mode/
GNU General Public License v3.0
1.33k stars 342 forks source link

Consider marking pragmas as something other than comments #1766

Open michaelpj opened 3 years ago

michaelpj commented 3 years ago

The root of this issue is that for lsp-mode-based completions, we would like to complete language pragmas. Since lsp-mode is quite generic, we don't have a good way of saying this, and we just have to say that we want completion in all comments. That is often quite annoying (https://github.com/emacs-lsp/lsp-haskell/issues/135).

@alanz made the suggestion that we could consider not treating pragmas as comments. I think that would mean a change to how haskell-mode tokenizes Haskell source, and ultimately I don't have a good sense of whether it would have lots of unintended consequences. But there is a certain logic to it: unlike normal comments, pragmas are active program elements that have a prescribed structure, and so in that sense are perhaps more like real syntax than comments.

As I said, I don't really know if this is a good idea or not, so I'd appreciate some wisdom!

alanz commented 3 years ago

FWIW I already have this customization:

'(haskell-pragma-face ((t (:inherit font-lock-preprocessor-face :foreground "royal blue"))))

So I think the underlying distinction is already being made.

michaelpj commented 3 years ago

Right, I meant to mention that: haskell-mode does give them different font-lock highlighting already. I don't understand enough about how syntax processing in emacs works to know what bit would need to change for them not to look like comments (although here is what lsp-mode does to distinguish comments: https://github.com/emacs-lsp/lsp-mode/blob/master/lsp-completion.el#L404).

purcell commented 3 years ago

This may be technically possible, but it seems like an indirect way to solve what is presumably an underlying issue with the LSP backend not completing very usefully inside comments.

michaelpj commented 3 years ago

Well, I'm not sure we'll ever get good completion inside comments. We probably just want to have it off. The problem is just that we can't distinguish that case from the weird case where we do want completions: pragmas. And I don't think we have enough context-sensitivity in how completions work in the LSP spec to notice whether or not we're in a comment...

purcell commented 3 years ago

You could be right, but on the other hand I'd be extremely surprised if the backend for lsp-java doesn't intelligently complete javadoc comment tags like @property, which I think would be similarly context-sensitive. I notice that that lsp-mode backend enables completion-in-comments.