AntlrVSIX icon indicating copy to clipboard operation
AntlrVSIX copied to clipboard

Need to work out protocol to determine "workspace".

Open kaby76 opened this issue 4 years ago • 1 comments

A client starts out an LSP session with the server with the Initialize call. This remote procedure call contains a "rootUri" string that specifies a directory for a "workspace". Unfortunately, the problem with this idea is that a directory is insufficient. The concept of what constitutes a program could be a solution file (.sln), a project file (.csproj), a Maven file (.pom), a CMake CMakeLists.txt file, or even a good ol' fashion Makefile. These files specify exactly what makes up a "workspace". I don't know why the designers decided that a directory is sufficient, or even relevant, to what is a program, what the components of a program are, and where to find them. But, this is what it is.

Right now, the code is implemented with the following assumptions:

  • "." contains all of the program source code;
  • the source is C#;
  • any Antlr "import" statements assume "." for finding the imported grammar;
  • any lexer grammar is in ".".

The problem with this is that doesn't work as well as it should. The code may not find the start symbol in the C# code, because I only do a Roslyn parse, not a full query.

I need to add to Antlrvsix a protocol to query from the client the program definition here. It is impossible for me to know what grammars to read, and it is only guessing otherwise.

kaby76 avatar Apr 16 '20 16:04 kaby76

According to https://github.com/microsoft/language-server-protocol/issues/703, it looks like what LSP designers want is "to use the workspace.getConfiguration() request" to help resolve opening a "workspace"--whatever that means, if anything at all. The rootUri is just a directory. But, since a directory can contain thousands of files that are not part of a particular program, the rootUri is basically useless non-information. I've seen a directory contain a .pom, .sln, and .csproj all in one lovely directory. Antlr is Antlr, but it could be targeted for any language, and it can contain target-specific action blocks. Believe me, Antlr breaks everything in LSP. So, when initializing, send a query to the client to figure out what the user is doing here, what the "workspace" really is, i.e., a .pom, a CMakeLists.txt, a makefile, a .sln, .csproj, whatever. Otherwise, you can't compile jack, you cannot find the Antlr generated Listeners or Visitors, can you determine the start symbol for the grammar because it's a method call in your damn program.

Once I have this worked out, I can then compile the program and determine the target language for the Antlr generator. I can then compile and search properly for all start symbols; I can perform tagging of action code blocks; I can change the name of visitors and listeners when renaming an grammar symbol.

kaby76 avatar Apr 18 '20 17:04 kaby76