Sarrus1 / sourcepawn-studio

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

Automatically set mainpath to current or first opened sp file #302

Closed ghost closed 1 year ago

ghost commented 1 year ago

What do you want to see added to the extension?

Automatically set mainpath to current or first opened sp file, not sure if this would be possible to do.

How would it help you?

I have multiple sp files in a single folder, such as the base addons/sourcemod/scripting, this would fix features that depend on mainpath.

How often would you use this feature?

All the time.

Sarrus1 commented 1 year ago

This is implemented in at least since 0.9.0 of the language server.

On startup, the server will scan all files in the workspace and try to match "OnPluginStart(". First file that matches is considered to be the main path. It is not perfect, and it is not intended to be, it's a heuristic.

It fails when trying to switch between mainPath (maybe this can be fine tuned to detect we are not in the scope of the mainPath anymore). It also fails if the mainPath does not actually contain "OnPluginStart(".