gleam-lang / gleam-mode

🐙 Gleam support for Emacs
Apache License 2.0
81 stars 23 forks source link

No syntax highlighting with gleam-mode #10

Open vbmithr opened 2 years ago

vbmithr commented 2 years ago

I have just installed gleam-mode followed the instruction, and it loads fine (gleam tree-sitter company) when I open a .gleam file but there is no syntax highlighting. Not sure how to fix this nor to give more debug info.

lpil commented 2 years ago

@gleam-lang/emacs-team Any ideas?

J3RN commented 2 years ago

Sorry for the delay on this!

@vbmithr Sadly getting this setup can be a bit of a pain. My first guess would be that the tree-sitter grammar was not compiled. You can check this by looking in the tree-sitter-gleam directory inside of where you cloned gleam-mode (e.g. if you cloned gleam-mode to ~/Code/gleam-mode/, look inside ~/Code/gleam-mode/tree-sitter-gleam). There should be a gleam.so file in there; if not, the grammar was not compiled.

Some reasons why that may have failed:


For whatever it's worth, a future revision will download a compiled asset instead of trying compile it on the host machine. The strength of the current approach is that it works anywhere a C compiler is available, whereas the downloading approach means that I'll have to maintain a repository of compiled assets for different OSes and architectures.

vbmithr commented 2 years ago

gleam.so is there. I’m using Linux. Current approach of compiling on host machine is fine for me! Also, I have checked that emacs indeed uses the file. Let me check with your latest commits.

vbmithr commented 2 years ago

Also, highighting works with tree-sitter cmdline program.

Bhanukamax commented 2 years ago

I have the same issue too, I have the gleam.so file in tree-sitter-gleam directory too, but syntax highlighting does not work. gleam-format is working fine. And I checked, tree-sitter does work for other languages.

J3RN commented 2 years ago

I have been able to replicate this issue in a bare-bones config, though I have syntax highlighting with the config I use daily. I'll be digging into this today to see if I can determine what setting I usually have enabled that causes syntax highlighting to work.

J3RN commented 2 years ago

Figured I'd post an update on debugging since it's taken awhile:

J3RN commented 2 years ago

I figured out what part of my config was causing syntax highlighting to work, and it's a doozy: whitespace-mode. If you don't mind @vbmithr, @Bhanukamax, try opening a Gleam file and enabling whitespace-mode (i.e. M-x whitespace-mode) to see if that triggers syntax highlighting. In my experience, syntax highlighting continues to function even when whitespace-mode is disabled, so long as it was at one time enabled in the buffer.

I honestly have no idea why syntax highlighting would be predicated on whitespace-mode, and I suspect that this is a bug upstream somewhere.

Bhanukamax commented 2 years ago

I figured out what part of my config was causing syntax highlighting to work, and it's a doozy: whitespace-mode. If you don't mind @vbmithr, @Bhanukamax, try opening a Gleam file and enabling whitespace-mode (i.e. M-x whitespace-mode) to see if that triggers syntax highlighting. In my experience, syntax highlighting continues to function even when whitespace-mode is disabled, so long as it was at one time enabled in the buffer.

I honestly have no idea why syntax highlighting would be predicated on whitespace-mode, and I suspect that this is a bug upstream somewhere.

wow!, that infact does it, thanks a lot, that's some weird stuff though, but it's great, finally, I get to see some gleam on its glory :slightly_smiling_face:. Thanks a lot @J3RN for looking into this.

vbmithr commented 2 years ago

I can confirm it works with whitespace-mode indeed.

quarkw commented 1 year ago

Sorry for the delay on this!

@vbmithr Sadly getting this setup can be a bit of a pain. My first guess would be that the tree-sitter grammar was not compiled. You can check this by looking in the tree-sitter-gleam directory inside of where you cloned gleam-mode (e.g. if you cloned gleam-mode to ~/Code/gleam-mode/, look inside ~/Code/gleam-mode/tree-sitter-gleam). There should be a gleam.so file in there; if not, the grammar was not compiled.

Some reasons why that may have failed:

  • No C compiler is available (which cc returns something like "no cc in: ...")
  • You're using Windows (I've never tested this on Windows, and I'm going to guess it doesn't work)

For whatever it's worth, a future revision will download a compiled asset instead of trying compile it on the host machine. The strength of the current approach is that it works anywhere a C compiler is available, whereas the downloading approach means that I'll have to maintain a repository of compiled assets for different OSes and architectures.

I feel dumb for not being able to figure this out, but how do I compile the grammar? I've checked and I have a C compiler. (which cc works for me), and I'm running on Mac OS. I can see that the gleam.so file is missing.

J3RN commented 1 year ago

@quarkw Are you using an M1/M2 mac? I only have access to an older Intel mac at the moment, but I can try to get ahold of an M1/M2 if that's the case.

quarkw commented 1 year ago

@quarkw Are you using an M1/M2 mac? I only have access to an older Intel mac at the moment, but I can try to get ahold of an M1/M2 if that's the case.

Ah yes, I’m on an M1 Mac. Usually I mention that in bug reports but forgot this time.

eppolito commented 1 year ago

Similar situation here, and it was a slight pain to fix it (and fair warning: I did it in the hackiest way possible). Here's a step-by-step in case someone else can benefit.

  1. Clone https://github.com/gleam-lang/tree-sitter-gleam and make a symlink to it in the gleam-mode directory you cloned from here (it wasn't cloned when I got gleam-mode from elpaca, but I might have written a bad recipe).
  2. In tree-sitter-gleam, run tree-sitter test. Note that you need to have tree-sitter-cli installed to do this (I got it from cargo, see https://github.com/tree-sitter/tree-sitter/blob/master/cli/README.md).
  3. The previous step should have generated gleam.so in your tree-sitter cache directory (for me, this is ~/.cache/tree-sitter/), as indicated here: https://github.com/tree-sitter/tree-sitter/issues/1868.
  4. Make a symlink to the gleam.so file in the tree-sitter-gleam directory.

After this, I just restart Emacs (or just revert the buffer), and I have all the goodies from tree-sitter-gleam running just fine.

slondr commented 6 months ago

Seeing this too, I have gleam.so in tree-sitter-gleam and the package loaded as per the Readme, no syntax highlighting in Gleam files and formatting seems super weird.

Edit:

Somehow rm -rfing my clone and recloning solved the issue for me.

vvzen commented 2 months ago

Just in case this helps Doom users out there, I was also having some troubles getting the syntax highlighting to work correctly, so I hacked my way through it.

After adding these 2 entries:

;; Gleam-lang support
(package! gleam-mode :recipe
  (:host github
   :repo "gleam-lang/gleam-mode"
   :files ("gleam-mode.el")))

(package! gleam-ts-mode :recipe
  (:host github
   :repo "gleam-lang/gleam-mode"
   :files ("gleam-ts-mode.el")))

I ran the usual doom sync && doom run. But when I was trying to activate gleam-mode from a doom session, I was getting this error in the Messages buffer:

gleam-mode--compile-grammar: Setting current directory: No such file or directory, /home/vv/.config/emacs/.local/straight/build-29.4/gleam-mode/tree-sitter-gleam/

I could repro that issue easily from a Elisp REPL:

(gleam-mode--compile-grammar)
*** Eval error ***  Setting current directory: No such file or directory, /home/vv/.config/emacs/.local/straight/build-29.4/gleam-mode/tree-sitter-gleam/

However, after looking in /home/vv/.config/emacs/.local/straight/repos/gleam-mode I saw that I do in fact have a tree-sitter-gleam directory there:

$ cd ~/.config/emacs/.local/straight
$ find . -type d -name 'tree-sitter-gleam'
./repos/gleam-mode/.git/modules/tree-sitter-gleam
./repos/gleam-mode/tree-sitter-gleam

So gleam-mode was looking in ~/.config/emacs/.local/straight/build-29.4/gleam-mode/tree-sitter-gleam

but the source code repo was actually installed in ~/.config/emacs/.local/straight/repos/gleam-mode/tree-sitter-gleam

So I just ran:

$ cd ~/.config/emacs/.local/straight/build-29.4/gleam-mode
$ ln -s ../../repos/gleam-mode/tree-sitter-gleam .

and then things started to work fine! I didn't have time to investigate more why gleam-mode was looking in that dir, and if that's a doom issue or a gleam-mode issue, but for now this works, and lets me hack with gleam, which was the original goal. Once I'll move to a new emacs version I'll just patch it again, I guess :D