Sarrus1 / sourcepawn-studio

VSCode extension for SourcePawn scripting
https://sarrus1.github.io/sourcepawn-studio/
MIT License
140 stars 22 forks source link

Function macro arguments highlighted incorrectly #333

Open DosMike opened 1 year ago

DosMike commented 1 year ago

Basic informations

Further Information

Usage of a function macro ignores the parens after and pulls symbol information from after the macro arcuments, making it look funny. If there's no more tokens in the line it just doesn't provide a tooltip at all, but coloring seems stable.

grafik

Omg most important feature, unworkable, 1 star on yelp 🤣

To Reproduce

  1. Create a function macro (#define something(%1) for(;(%1);(%1)--))
  2. Use macro (something(number) PrintToServer("%i", number);)

Code to reproduce the behaviour

#define forEach(%1,%2) for (int %2 ; %2 < (%1).Length ; %2 += 1)
ArrayList list1 = new ArrayList();
ArrayList list2 = new ArrayList();
forEach(list1, i) list2.Push(list1.Get(i));

Expected behaviour

Type hints and colors on marco arguments should work

Sarrus1 commented 10 months ago

This is due to how macros are expanded. The server sees the macros as expanded, so it thinks that there is a for instead of forEach in your example, thus the incorrect highlighting. I think this can be sorted by keeping a sorted array of the expanded macros, and checking that the symbols that are highlighted are not stepping on another symbol.