KubaP / glsl-lsp

A language server implementation for the OpenGL Shading Langauge, written in Rust.
12 stars 1 forks source link

Support custom preprocessor directives #17

Open KubaP opened 6 months ago

KubaP commented 6 months ago

For the purposes of this project, custom preprocessor directives are defined as preprocessor directives not part of the GLSL specification. Whilst such directives are, obviously, technically illegal, it is not unthinkable that some people may have their own (pre-)preprocess step that uses custom directives to control something, (and said step also strips out these directives to produce a valid GLSL file).

Since this is a non-standard feature, we control the design. To keep things simple and avoid unexpected behaviour, custom preprocessor directives must start with a name that conforms to an identifier: must contain only a..z | A..Z | _. If a custom preprocessor directive is found and allowed, any tokens, even invalid ones, are allowed to follow the name of the directive; no error checking of any kind will happen, and the library/server will effectively completely ignore it (other than modelling it in the AST).

Since this is a non-standard feature, it must be opt-in. We could just have an on/off toggle, but it would be better to allow the user to define a list of custom directive names that should be accepted. From the perspective of the library, this would probably just be a [&str] given to the parser/lexer. From the perspective of the server, this would have to be some sort of "project" configuration; maybe something like glsl-lsp.project.customDirectives = ["foo", "bar"].

Tasks