haskell-mode icon indicating copy to clipboard operation
haskell-mode copied to clipboard

Consider marking pragmas as something other than comments

Open michaelpj opened this issue 4 years ago • 5 comments

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!

michaelpj avatar Oct 07 '21 10:10 michaelpj

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.

alanz avatar Oct 07 '21 10:10 alanz

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).

michaelpj avatar Oct 07 '21 10:10 michaelpj

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.

purcell avatar Oct 07 '21 15:10 purcell

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...

michaelpj avatar Oct 07 '21 16:10 michaelpj

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.

purcell avatar Oct 08 '21 14:10 purcell