onivim / oni

Oni: Modern Modal Editing - powered by Neovim
https://www.onivim.io
MIT License
11.35k stars 299 forks source link

Syntax Highlighting: Use with `<c-/>` command #2058

Open bryphe opened 6 years ago

bryphe commented 6 years ago

There is a somewhat undocumented command which is like an enhanced find-in-buffer experience, accessible via <c-/>:

super-search

It's a really cool feature! The only downside with it is that it doesn't respect syntax highlighting. I believe that with the work we have in the textmate highlighting feature, it should be possible to get syntax highlighting here.

We expose an API for querying the tokens / highlights as a syntaxHighlighter object off of he editors: https://github.com/onivim/oni/blob/a99544bdffbceb07c86a1f8c0da614ef7c2e4f52/browser/src/Editor/NeovimEditor/NeovimEditor.tsx#L175

And that has a method for getHighlightTokenAt: https://github.com/onivim/oni/blob/a99544bdffbceb07c86a1f8c0da614ef7c2e4f52/browser/src/Services/SyntaxHighlighting/SyntaxHighlighting.ts#L116

But, we also have the full set of tokens on the line - so it might be worth creating an API like getTokensForLine(bufferId, lineNumber) - if we had that, it should be pretty straightforward to get the token colors and show some nice syntax highlighting here 👍

bryphe commented 6 years ago

The <c-/> code is mixed in with the QuickOpen functionality here: https://github.com/onivim/oni/blob/master/browser/src/Services/QuickOpen/QuickOpen.ts

Might also be a good opportunity to refactor it out it into its own module.

akinsho commented 6 years ago

@bryphe whilst working on the hover syntax highlighting I developed this which is a function that can be used to get tokens for any kind of line given some arguments.

This would definitely work quite well there, and actually given that they are all dom elements, the same system as for hover highlighting could be used there