Sarrus1 / sourcepawn-lsp

Language Server Protocol implementation for the SourcePawn programming language written in Rust
GNU General Public License v3.0
12 stars 0 forks source link

Semantic analysis may break when a token is renamed in another file #12

Closed Sarrus1 closed 1 year ago

Sarrus1 commented 1 year ago

Description

Source creation 🚩

  1. File B references a methodmap called Foo which should be declared in file A but isn't.
  2. Declare methodmap Foo in file A.
  3. File B is only reparsed when it is modified. The references of methodmap Foo are no synced.

Source deletion 🚩

  1. File B references a methodmap called Foo which is declared in file A.
  2. Delete the declaration of the Foo methodmap.
  3. The references are deleted with the object, the references of methodmap Foo are synced.
  4. The missing references are not reported.

Reference creation ✔️

  1. Methodmap Foo is declared in file A.
  2. File B is edited and references Foo.
  3. The references are updated in the semantic analysis, the references of methodmap Foo are synced.

Reference deletion ✔️

  1. Methodmap Foo is declared in file A and is referenced in file B.
  2. File B is edited and no longer references Foo.
  3. The references are updated in the semantic analysis by purge_references, the references of methodmap Foo are synced.

Potential fix

Greedy approach

Mark the file as "missing resolutions" and whenever a file is edited, reparse all files which are marked as "missing resolutions". This will add a lot of unnecessary computations. Needs some testing. Doing it on saves only might be more reasonable.

Lazy approach

Keep a hashset of the non-resolved tokens. If one of the top level tokens of file B is in the hashset of file A, trigger a reparse. Maybe keep the scope in a hashmap to resume the semantic analysis rather than starting from zero.