usethesource / rascal-language-servers

An LSP server for Rascal which includes an easy-to-use LSP generator for languages implemented in Rascal, and an interactive terminal REPL.
BSD 2-Clause "Simplified" License
10 stars 7 forks source link

Can't import `util::LanguageServer` in fresh terminal #291

Closed aukeroorda closed 1 year ago

aukeroorda commented 1 year ago

Describe the bug

My project stopped working, as the import of the module util::LanguageServer inside my code fails. Opening a fresh rascal terminal and importing the module results in the same errors. This started 15 minutes ago, after daily and continued use of this library for the past week.

To Reproduce

Steps to reproduce the behavior:

  1. Open a fresh rascal terminal in VScode
  2. import util::LanguageServer;
  3. See error in? REPL

Expected behavior I expect the util::LanguageServer import to work.

Stack traces

INFO: detected |lib://rascal-lsp| at |jar+file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.8.3/assets/jars/rascal-lsp.jar!/|
INFO: detected |lib://rascal| at |jar+file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.8.3/assets/jars/rascal.jar!/|
INFO: resolved |lib://rascal-lsp| at |jar+file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.8.3/assets/jars/rascal-lsp.jar!/|
Rascal Version: 0.33.5
Rascal-lsp Version: 2.17.2
pathConfig(
  ignores=[],
  javaCompilerPath=[
    |file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.8.3/assets/jars/rascal-lsp.jar|,
    |file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.8.3/assets/jars/rascal.jar|
  ],
  bin=|target://salix-corel|,
  classloaders=[
    |target://salix-corel|,
    |system:///|,
    |lib://rascal-lsp|
  ],
  libs=[|lib://rascal|],
  srcs=[
    |lib://rascal-lsp|,
    |file:///Users/auke/salix-corel/src/main/rascal|
  ])INFO: resolved |lib://rascal| at |jar+file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.8.3/assets/jars/rascal.jar!/|
rascal>import util::LanguageServer;
|std:///lang/rascal/grammar/definition/Keywords.rsc|(370,12,<12,0>,<12,12>):Could not load Node due to: Module name salix::Node does not match Node
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/ModuleNameMismatch| at |std:///lang/rascal/grammar/definition/Keywords.rsc|(370,12,<12,0>,<12,12>)
|std:///lang/rascal/grammar/definition/Keywords.rsc|(370,12,<12,0>,<12,12>):Module name salix::Node does not match Node
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/ModuleNameMismatch|
|std:///lang/rascal/grammar/ParserGenerator.rsc|(1180,12,<31,0>,<31,12>):Could not load Node due to: Module name salix::Node does not match Node
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/ModuleNameMismatch| at |std:///lang/rascal/grammar/ParserGenerator.rsc|(1180,12,<31,0>,<31,12>)
|std:///lang/rascal/grammar/ParserGenerator.rsc|(1180,12,<31,0>,<31,12>):Module name salix::Node does not match Node
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/ModuleNameMismatch|
|std:///lang/rascal/grammar/definition/Keywords.rsc|(370,12,<12,0>,<12,12>):Could not load Node due to: Module name salix::Node does not match Node
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/ModuleNameMismatch| at |std:///lang/rascal/grammar/definition/Keywords.rsc|(370,12,<12,0>,<12,12>)
|std:///lang/rascal/grammar/definition/Keywords.rsc|(370,12,<12,0>,<12,12>):Module name salix::Node does not match Node
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/ModuleNameMismatch|
|prompt:///|(0,28,<1,0>,<1,28>):Could not load util::LanguageServer due to: Undeclared variable: unsetRec
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/UndeclaredVariable| at |std:///lang/rascal/grammar/ParserGenerator.rsc|(13469,8,<291,32>,<291,40>)
|std:///lang/rascal/grammar/ParserGenerator.rsc|(13469,8,<291,32>,<291,40>): Undeclared variable: unsetRec
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/UndeclaredVariable|
ok
rascal>

Desktop (please complete the following information):

DavyLandman commented 1 year ago

Have you tried updating to the lastest rascal-lsp? v0.9.0 was released in companion to the newest rascal release, and rascal-vscode extension.

jurgenvinju commented 1 year ago

This looks rather iffy. Let's try and have a call on Monday?

jurgenvinju commented 1 year ago

Is there a module called Node in your project, without any folder around it? I think this may break the loading of util::LanguageServer because it imports Node from the standard library. Somehow the latest release changed the order in the search path and that leads to this problem.

jurgenvinju commented 1 year ago

Other library modules that import Node run into similar issues as you can see.

aukeroorda commented 1 year ago

Hi - Thanks for looking into this so quick!

Have you tried updating to the lastest rascal-lsp? v0.9.0 was released in companion to the newest rascal release, and rascal-vscode extension.

This solves the issue of solely importing `util::LanguageServer`
INFO: detected |lib://rascal-lsp| at |jar+file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.9.0/assets/jars/rascal-lsp.jar!/|
INFO: detected |lib://rascal| at |jar+file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.9.0/assets/jars/rascal.jar!/|
INFO: resolved |lib://rascal-lsp| at |jar+file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.9.0/assets/jars/rascal-lsp.jar!/|
Rascal Version: 0.33.7
Rascal-lsp Version: 2.18.0
pathConfig(
  ignores=[],
  javaCompilerPath=[
    |file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.9.0/assets/jars/rascal-lsp.jar|,
    |file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.9.0/assets/jars/rascal.jar|
  ],
  bin=|target://salix-corel|,
  classloaders=[
    |target://salix-corel|,
    |system:///|,
    |lib://rascal-lsp|
  ],
  libs=[|lib://rascal|],
  srcs=[
    |lib://rascal-lsp|,
    |file:///Users/auke/salix-corel/src/main/rascal|
  ])INFO: resolved |lib://rascal| at |jar+file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.9.0/assets/jars/rascal.jar!/|
rascal>import util::LanguageServer;
ok
rascal>

However,

Is there a module called Node in your project, without any folder around it? I think this may break the loading of util::LanguageServer because it imports Node from the standard library. Somehow the latest release changed the order in the search path and that leads to this problem.

This is almost the case, as there is a module module salix::Node in my project, but inside the salix directory.

tree of the `src` directory. ``` > tree src src └── main └── rascal ├── Frink.rsc ├── FrinkRascalUnits.rsc ├── Helpers.rsc ├── Main.rsc ├── corel │   ├── AST.rsc │   ├── CST2AST.rsc │   ├── Check.rsc │   ├── CorelLanguageServer.rsc │   ├── Syntax.rsc │   ├── Syntax_t.rsc │   ├── editor │   │   ├── Demo.rsc │   │   ├── LspWebEditor.rsc │   │   ├── Model.rsc │   │   ├── RecipeView.rsc │   │   ├── android-chrome-192x192.png │   │   ├── android-chrome-512x512.png │   │   ├── apple-touch-icon.png │   │   ├── curry-madras.crl │   │   ├── favicon-16x16.png │   │   ├── favicon-32x32.png │   │   ├── favicon.ico │   │   ├── script.js │   │   ├── site.webmanifest │   │   └── style.css │   ├── runtime-data │   │   └── frink-units.txt │   └── salix.js └── salix ├── App.rsc ├── Core.rsc ├── Diff.rsc ├── HTML.rsc ├── Index.rsc ├── LspData.rsc ├── Node.rsc ├── SVG.rsc ├── ace │   ├── Demo.rsc │   └── Editor.rsc ├── charts │   ├── Charts.rsc │   └── Demo.rsc ├── cytoscape │   ├── Cytoscape.rsc │   └── Demo.rsc ├── demo │   ├── alien │   │   └── Prototype.rsc │   ├── basic │   │   ├── All.rsc │   │   ├── Celsius.rsc │   │   ├── Clock.rsc │   │   ├── Counter.rsc │   │   ├── Loop.rsc │   │   └── Random.rsc │   ├── shop │   │   ├── Shop.rsc │   │   └── test.css │   └── todomvc │   ├── TodoMVC.rsc │   └── style.css ├── mermaid │   ├── ClassDiagram.rsc │   ├── Demo.rsc │   ├── FlowChart.rsc │   └── Mermaid.rsc ├── salix.js └── util ├── Debug.rsc ├── Highlight.rsc └── Mode.rsc 17 directories, 59 files ```

For this comment I was trying to construct a minimal reproducible example, as the error still occurred when trying to import a module that used util::LanguageServer, or so I thought. In the process of constructing a minimal reproducible example, I cleared and restarted my terminal a couple of times, so I cannot provide the exact steps I did :(.

I started by importing my main module, that imports a bunch of other modules. The error stated that an import could not be loaded, so I went on and tried manually importing that module directly in the REPL. This then gave me a next module that could not be imported, until I eventually reached a single 'leaf' module that did not import any other modules, my corel::Syntax module. After finally importing this in the REPL, the error went away. The error was in the form of:

|prompt:///|(0,28,<1,0>,<1,28>):Could not load util::LanguageServer due to: Undeclared variable: unsetRec
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/UndeclaredVariable| at |std:///lang/rascal/grammar/ParserGenerator.rsc|(13469,8,<291,32>,<291,40>)
|std:///lang/rascal/grammar/ParserGenerator.rsc|(13469,8,<291,32>,<291,40>): Undeclared variable: unsetRec
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/UndeclaredVariable|
jurgenvinju commented 1 year ago

Mysterious! If we ever end up in this corner again, let's reopen the issue. Thanks for the info @aukeroorda

aukeroorda commented 1 year ago

When working on the project today, the issue has reappeared, as in, it is the same set of errors, but for a different module. There is a very strange inconsistency, as there is a simple module that can be imported in a fresh REPL, but not in one where the issue with the node module name mismatch has occurred. This is what I have done:

Open project in vscode, click Import in new Rascal Terminal on `LspData.rsc` ``` INFO: detected |lib://rascal-lsp| at |jar+file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.9.0/assets/jars/rascal-lsp.jar!/| INFO: detected |lib://rascal| at |jar+file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.9.0/assets/jars/rascal.jar!/| INFO: resolved |lib://rascal-lsp| at |jar+file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.9.0/assets/jars/rascal-lsp.jar!/| Rascal Version: 0.33.7 Rascal-lsp Version: 2.18.0 pathConfig( ignores=[], javaCompilerPath=[ |file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.9.0/assets/jars/rascal-lsp.jar|, |file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.9.0/assets/jars/rascal.jar| ], bin=|target://salix-corel|, classloaders=[ |target://salix-corel|, |system:///|, |lib://rascal-lsp| ], libs=[|lib://rascal|], srcs=[ |lib://rascal-lsp|, |file:///Users/auke/salix-corel/src/main/rascal| ])INFO: resolved |lib://rascal| at |jar+file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.9.0/assets/jars/rascal.jar!/| rascal>import salix::LspData; |std:///lang/rascal/grammar/definition/Keywords.rsc|(370,12,<12,0>,<12,12>):Could not load Node due to: Module name salix::Node does not match Node Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/ModuleNameMismatch| at |std:///lang/rascal/grammar/definition/Keywords.rsc|(370,12,<12,0>,<12,12>) |std:///lang/rascal/grammar/definition/Keywords.rsc|(370,12,<12,0>,<12,12>):Module name salix::Node does not match Node Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/ModuleNameMismatch| |std:///lang/rascal/grammar/ParserGenerator.rsc|(1180,12,<31,0>,<31,12>):Could not load Node due to: Module name salix::Node does not match Node Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/ModuleNameMismatch| at |std:///lang/rascal/grammar/ParserGenerator.rsc|(1180,12,<31,0>,<31,12>) |std:///lang/rascal/grammar/ParserGenerator.rsc|(1180,12,<31,0>,<31,12>):Module name salix::Node does not match Node Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/ModuleNameMismatch| |std:///lang/rascal/grammar/definition/Keywords.rsc|(370,12,<12,0>,<12,12>):Could not load Node due to: Module name salix::Node does not match Node Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/ModuleNameMismatch| at |std:///lang/rascal/grammar/definition/Keywords.rsc|(370,12,<12,0>,<12,12>) |std:///lang/rascal/grammar/definition/Keywords.rsc|(370,12,<12,0>,<12,12>):Module name salix::Node does not match Node Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/ModuleNameMismatch| |file:///Users/auke/salix-corel/src/main/rascal/salix/LspData.rsc|(444,21,<13,0>,<13,21>):Could not load corel::Syntax due to: Undeclared variable: unsetRec Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/UndeclaredVariable| at |std:///lang/rascal/grammar/ParserGenerator.rsc|(13426,8,<290,32>,<290,40>) |file:///Users/auke/salix-corel/src/main/rascal/salix/LspData.rsc|(444,21,<13,0>,<13,21>):Undeclared variable: unsetRec Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/UndeclaredVariable| ok rascal> ``` Note that there are three occurences of `Could not load Node due to: Module name salix::Node does not match Node`, and a different last one: ``` |file:///Users/auke/salix-corel/src/main/rascal/salix/LspData.rsc|(444,21,<13,0>,<13,21>):Could not load corel::Syntax due to: Undeclared variable: unsetRec Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/UndeclaredVariable| at |std:///lang/rascal/grammar/ParserGenerator.rsc|(13426,8,<290,32>,<290,40>) |file:///Users/auke/salix-corel/src/main/rascal/salix/LspData.rsc|(444,21,<13,0>,<13,21>):Undeclared variable: unsetRec Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/UndeclaredVariable| ``` This one is strange, as the module `corel::Syntax` does not contain a variable (or the string) `unsetRec`.
`corel::Syntax` module ```rascal module corel::Syntax extend lang::std::Layout; /* A recipe should mostly be proza, except for some key elements: * - A header indicator followed by the title of the recipe: # Bolognese * - A subsection indicating the list of ingredients: ## Ingredients * - A subsection containing the instructions: ## Instructions */ start syntax Recipe = | empty: | syn: Synopsis synopsis | syn_ing: Synopsis synopsis Ingredients ingredients [\n]* | syn_ing_ins: Synopsis synopsis Ingredients ingredients Instructions instructions [\n]* ; /* The synopsis of is required to contain the name, and possibly: * - [ ] Number of servings: Servings: 4-6 * - [ ] or a yield: Yield: 4 plates * - [ ] And proza, such as a description */ syntax Synopsis = ^"#" RestOfLine name ; /* The ingredients section contains a list of ingredients. */ syntax Ingredients = ^"##" RestOfLine ingredients_header Ingredient* list; /* The instructions are a list of free text instructions. */ syntax Instructions = ^"##" RestOfLine instructions_header Instruction* list; // Ingredient building blocks syntax Ingredient = ^'-' Word* words; syntax Word = quantity: Quantity quantity // Starts and ends with '[]' | ingredient_def: IngredientDef ingredient_def // Starts and ends with '{}' | ingredient_ref: IngredientRef ingredient_ref // Starts and ends with '@@' | time: Time time // Starts and ends with '||' | temperature: Temperature temperature // Starts and ends with '<>' | description_text: DescriptionText description_text // Starts and ends with remaining characters ; syntax Quantity = @category="Type" exact: '[' NumberOrRange val QuantityUnit unit ']' | @category="Type" count: '[' NumberOrRange val ']' | @category="Type" unit: '[' QuantityUnit unit ']' | @category="Type" empty: '[' ']' ; // Instruction building blocks /* Instructions are generally grouped in paragraphs of multiple sentences. Each paragraph has to start with a dash `-`. */ syntax Instruction = ^'-' Word* words; // Syntactic building blocks syntax NumberOrRange = @category="Constant" number: ExactValue val | @category="Constant" range: ExactValue lower '-' ExactValue upper ; syntax ExactValue = sole_integral: NaturalNumber nat | mixed: NaturalNumber nat Fraction frac | sole_fraction: Fraction frac ; // Lexical building blocks /* RestOfLine matches anything from the current location up to the first newline char */ lexical RestOfLine = ![\n]+ !>> ![\n]; /* Fractions in the form: "1/2", no whitespace allowed */ lexical Fraction = NaturalNumber numerator '/' NaturalNumber denominator; /* Natural numbers, so no negative numbers or decimals. Always starts with a non-zero digit. Is never preceded or followed by a digit. */ lexical NaturalNumber = [0-9] !<< ([1-9][0-9]*) val !>> [0-9]; /* Matches any proza up to the first newline or delimiting character. */ lexical DescriptionText = @category="Identifier" ( ![#\-@|\<{\[\n] // Cannot contain delimiting characters OR a dash as first char ![@|\<{\[\n]* // and no delimiting characters later on ) text !>> ![@|\<{\[\n] // and ensures the longest match ; /* Ingredient definitions are delimited by curly braces {}. The name cannot contain any of the delimiting characters. */ lexical IngredientDef = @category="Comment" "{" IngredientIdentifier name "}" | @category="Comment" empty: "{" "}" ; /* Ingredient references are enclosed with @. The name follows the same specification as the ingredient definitions. */ lexical IngredientRef = @category="Comment" "@" IngredientIdentifier name "@" | @category="Comment" empty: "@" "@" ; /* The ingredient identifiers are any characters that are not a newline, and also not any of the delimiting characters. */ lexical IngredientIdentifier = (![\n] - [{}@0-9]) // Atleast a single character long. Cannot start with a digit. (![\n] - [{}@])* // Followed by one or more characters !>> ![\n] - [{}@]; // And not directly succeeded by any of the non-delimiting characters. /* Temperatures are delimited by angled brackets <>, e.g. <400 F> */ syntax Temperature = @category="Type" exact: "\<" NumberOrRange val TemperatureUnit unit "\>" | @category="Type" count: "\<" NumberOrRange val "\>" | @category="Type" unit: "\<" TemperatureUnit unit "\>" | @category="Type" empty: "\<" "\>" ; /* Times are enclosed in pipes ||, e.g. |5 minutes|. */ syntax Time = @category="Type" exact: "|" NumberOrRange val TimeUnit unit "|" | @category="Type" count: "|" NumberOrRange val "|" | @category="Type" unit: "|" TimeUnit unit "|" | @category="Type" empty: "|" "|" ; /* Unit strings are very flexible, but don't allow numbers or the following delimiter */ lexical QuantityUnit = ![0-9\]\n]+ !>> ![\]]; lexical TemperatureUnit = ![0-9\>\n]+ !>> ![\>]; lexical TimeUnit = ![0-9|\n]+ !>> ![|]; ```
However, this time, directly importing the module `corel::Syntax` (in the same REPL instance as before) does not resolve the issue: ``` rascal>import corel::Syntax; |prompt:///|(0,21,<1,0>,<1,21>):Could not load corel::Syntax due to: Undeclared variable: unsetRec Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/UndeclaredVariable| at |std:///lang/rascal/grammar/ParserGenerator.rsc|(13426,8,<290,32>,<290,40>) |std:///lang/rascal/grammar/ParserGenerator.rsc|(13426,8,<290,32>,<290,40>): Undeclared variable: unsetRec Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/UndeclaredVariable| ok rascal> ``` __But then__, going to the `corel::Syntax` module and clicking import in new Rascal terminal works! ``` INFO: detected |lib://rascal-lsp| at |jar+file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.9.0/assets/jars/rascal-lsp.jar!/| INFO: detected |lib://rascal| at |jar+file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.9.0/assets/jars/rascal.jar!/| INFO: resolved |lib://rascal-lsp| at |jar+file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.9.0/assets/jars/rascal-lsp.jar!/| Rascal Version: 0.33.7 Rascal-lsp Version: 2.18.0 pathConfig( ignores=[], javaCompilerPath=[ |file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.9.0/assets/jars/rascal-lsp.jar|, |file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.9.0/assets/jars/rascal.jar| ], bin=|target://salix-corel|, classloaders=[ |target://salix-corel|, |system:///|, |lib://rascal-lsp| ], libs=[|lib://rascal|], srcs=[ |lib://rascal-lsp|, |file:///Users/auke/salix-corel/src/main/rascal| ])INFO: resolved |lib://rascal| at |jar+file:///Users/auke/.vscode/extensions/usethesource.rascalmpl-0.9.0/assets/jars/rascal.jar!/| rascal>import corel::Syntax; ok rascal> ```

If you'd like, and have the time, you could join the meeting I have with @tvdstorm today, at 1pm.

aukeroorda commented 1 year ago

I'll see what renaming the salix::Node module achieves, and whether adding a pom file solves this issue. I've added you as collaborator to the project in which I'm working @jurgenvinju.

jurgenvinju commented 1 year ago

Bug reproduced here.

jurgenvinju commented 1 year ago

having or not-having a pom.xml in the project makes no difference

aukeroorda commented 1 year ago

Renaming the salix::Node module to salix::NamechangedNode works. Use the shell script namechangecommand.sh on the rename-salix-node branch if you want to reproduce: https://github.com/aukeroorda/salix-corel/tree/rename-salix-node

Note that this changed module name still ends in Node, but the name itself is prefixed.

jurgenvinju commented 1 year ago

Ok.

found : |std:///ListRelation.rsc|
found : |cwd:///Node.rsc|
|std:///vis/Text.rsc|(948,12,<27,0>,<27,12>):Could not load Node due to: Module name salix::Node does not match Node
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/ModuleNameMismatch| at |std:///vis/Text.rsc|(948,12,<27,0>,<27,12>)
|std:///vis/Text.rsc|(948,12,<27,0>,<27,12>):Module name salix::Node does not match Node
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/ModuleNameMismatch|
ok
rascal>|cwd:///|.ls
list[loc]: [
  |cwd:///demo|,
  |cwd:///HTML.rsc|,
  |cwd:///LspData.rsc|,
  |cwd:///util|,
  |cwd:///Node.rsc|,
  |cwd:///cytoscape|,
  |cwd:///SVG.rsc|,
  |cwd:///Core.rsc|,
  |cwd:///charts|,
  |cwd:///App.rsc|,
  |cwd:///Diff.rsc|,
  |cwd:///salix.js|,
  |cwd:///Index.rsc|,
  |cwd:///mermaid|,
  |cwd:///ace|
]
rascal>import Location;
found : |std:///Location.rsc|
found : |std:///Set.rsc|
found : |std:///String.rsc|
ok
rascal>import IO;
found : |std:///IO.rsc|
ok
rascal>resolveLocation(|cwd:///|)
loc: |file:///Users/jurgenv/git/salix-corel/src/main/rascal/salix/|
jurgenvinju commented 1 year ago

So the CWD is also on the path, and this breaks the module resolution code.

jurgenvinju commented 1 year ago
  private registerMainRun() {
        this.context.subscriptions.push(
            vscode.commands.registerTextEditorCommand("rascalmpl.runMain", (text, _edit, moduleName) => {
                if (!text.document.uri || !moduleName) {
                    return;
                }
                this.startTerminal(text.document.uri, "--loadModule", moduleName, "--runModule"); // here we pass the URI that becomes the CWD
            })
        );
    }

    private registerImportModule() {
        this.context.subscriptions.push(
            vscode.commands.registerTextEditorCommand("rascalmpl.importModule", (text, _edit, moduleName) => {
                if (!text.document.uri || !moduleName) {
                    return;
                }
                this.startTerminal(text.document.uri, "--loadModule", moduleName); // here we pass the URI that becomes the CWD
            })
        );
    }

This is the cause in RascalExtension.ts

jurgenvinju commented 1 year ago

the parent of text.document.uri is used as the cwd

jurgenvinju commented 1 year ago
  private startTerminal(uri: vscode.Uri | undefined, ...extraArgs: string[]) {
        return vscode.window.withProgress({
            location: vscode.ProgressLocation.Notification,
            cancellable: false,
            title: "Rascal terminal"
        }, async (progress) => {
            progress.report({message: "Starting rascal-lsp"});
            const rascal = await this.rascal.rascalClient;
            console.log(`Starting Rascal REPL: on ${uri} and with args: ${extraArgs}`);
            if (uri && !uri.path.endsWith(".rsc")) {
                // do not try to figure out a rascal project path when the focus is not a rascal file
                uri = undefined;
            }
            progress.report({increment: 25, message: "Requesting IDE configuration"});
            const serverConfig = await rascal.sendRequest<IDEServicesConfiguration>("rascal/supplyIDEServicesConfiguration");
            progress.report({increment: 25, message: "Calculating project class path"});
            const compilationPath = await rascal.sendRequest<string[]>("rascal/supplyProjectCompilationClasspath", { uri: uri?.toString() });
            progress.report({increment: 25, message: "Creating terminal"});
            const terminal = vscode.window.createTerminal({
                iconPath: this.icon,
                cwd: path.dirname(uri?.fsPath || ""), // this is where we use the given uri for the CWD
                shellPath: await getJavaExecutable(),
                shellArgs: this.buildShellArgs(compilationPath, serverConfig, ...extraArgs),
                name: 'Rascal Terminal',
            });

            terminal.show(false);
            progress.report({increment: 25, message: "Finished creating terminal"});
        });
    }

So know we know everything. All we need is a fix.

jurgenvinju commented 1 year ago

In reality the CWD here should not be anything related to the project or another library. The user's home directory would be fine.

jurgenvinju commented 1 year ago

@tvdstorm @aukeroorda the problem is now diagnosed; thinking about the solution.

jurgenvinju commented 1 year ago

@aukeroorda workaround: if you start a terminal from a module (parent folder) that does not contain a Node module, there is no such effect.

jurgenvinju commented 1 year ago

The fix fixes the problem; tested this here.

DavyLandman commented 12 months ago

v0.9.1 is released to include this bugfix. Thanks @aukeroorda for the clear bug reports and patience in testing.