JuliaEditorSupport / julia-vim

Vim support for Julia.
http://julialang.org/
Other
753 stars 94 forks source link

Wrong parsing of highlight groups for functions in assignment form #234

Closed mroavi closed 3 years ago

mroavi commented 3 years ago

This is a function definition in assignment form:

add(a,b) = a + b

add is highlighted as a juliaModuleBlock while it should be highlighted as a juliaFunctionName.

Another case:

Base.IndexStyle() = Base.IndexLinear()

IndexStyle is highlighted as juliaBaseTypeArray while I think it should be juliaFunctionName.

carlobaldassi commented 3 years ago

These should be fixed by #231 (they will actually all be highlighted as JuliaFunctionCall).

mroavi commented 3 years ago

This line shows up in my highlights:

image (I also tried the typo version JuliaFuncionCall that you wrote above, but got the same results)

and here is how the examples above appear highlighted:

image image

So this is why I don't think it is fixed. Could it be that I'm doing something wrong?

mroavi commented 3 years ago

By the way, the piece of code I showed above is not a function call but rather a function definition (one with shorter syntax than the one that uses the function keyword, but they are equivalent)

carlobaldassi commented 3 years ago

Yes, but it will be fixed if/when #231 is merged. As for detecting function definitions performed with assignments, I think it's basically impossible to do in any reasonable way with vim, because the = sign that determines the interpretation comes an arbitrary number of tokens after the function name, and thus the highlighting would need to go backwards (whereas vim highlighting proceeds in the forward direction only, with some very, very limited and expensive looking-back capabilities).

mroavi commented 3 years ago

Ohh I see. Thanks for the clarification!

mroavi commented 3 years ago

Sorry to bother you again but the problem doesn't seem to be fixed with the new updates:

image

The left product is a function name definition and should be highlighted with juliaFunctionName. The product in the right is a function call and it is correctly highlighted with juliaFunctionCall

mroavi commented 3 years ago

These two function definitions are equivalent, and hence should have the same color highlighting:

image

image

carlobaldassi commented 3 years ago

As for detecting function definitions performed with assignments, I think it's basically impossible to do in any reasonable way with vim, because the = sign that determines the interpretation comes an arbitrary number of tokens after the function name, and thus the highlighting would need to go backwards (whereas vim highlighting proceeds in the forward direction only, with some very, very limited and expensive looking-back capabilities).

mroavi commented 3 years ago

Ohh right. Sorry I missed that. Completely forgot about it. Hmm I wonder how VS Code or Atom do it.

mroavi commented 3 years ago

Would it be helpful if I ask one of the maintainers?

carlobaldassi commented 3 years ago

I think that they have a running julia session and leverage Julia itself for determining the syntactic role of each token. This is not how syntax highlighting (currently) works in vim.

pfitzseb commented 3 years ago

No, VSCode's syntax highlighting is regex based as well. We're matching short-form function definitions with this, which works ok in many cases (but can also very easily break, see e.g. https://github.com/JuliaEditorSupport/atom-language-julia/issues/240). AFAICT vim's regex engine supports both positive and negative lookaheads, so a similar implementation should be possible here as well.

carlobaldassi commented 3 years ago

Ah I see, thanks for correcting me. Anyway, the problem with that regex is the arguments part \\(.*\\) which is what can so easily break. To do it right (in vim) one has to use a syntax region, opened by something like "identifier(" and ended by ") =", but the opening matches both a function call and a function def, and there is no way to discriminate based on the ending part. And I can't think of any work around to obtain that effect.