Skip to content

projectMapping doesn't work for the first opened file #303

Open
@khaledh

Description

@khaledh

I noticed that the first file I open in VSCode creates a nimsuggest process for that specific file, not the associated project file. When I later open other files, their nimsuggest instance uses the associated project file correctly.

// settings.json
{
  "nim.projectMapping": [
    {
        "projectFile": "src/kernel/main.nim",
        "fileRegex": "src/(kernel|common)/.*\\.nim"
    }
  ]
}
DBG Starting nimlangserver                     version=1.10.0 params="(clientProcessId: none(int), transport: some(stdio), port: 0)"
DBG Starting stdio server                     
DBG [Processsing Message]                      request="\"initialize\""
DBG Initialize received...                    
DBG Registering monitor for process            pid=84584
DBG Initialize completed. Trying to start nimsuggest instances
DBG Trying to start nimsuggest instances done 
DBG [Processsing Message]                      request="\"initialized\""
DBG Requesting configuration from the client  
DBG [Processsing Message]                      request="\"textDocument/didOpen\""
DBG New document opened for URI:               uri=file:///Users/khaled/src/khaledh/fusion/src/common/segtree.nim
DBG Auto-guessing project file for             file=/Users/khaled/src/khaledh/fusion/src/common/segtree.nim
DBG getProjectFile                             project=/Users/khaled/src/khaledh/fusion/src/common/segtree.nim fileUri=/Users/khaled/src/khaledh/fusion/src/common/segtree.nim

Notice that it says Auto-guessing project file, when it should rely on the project mapping config. The next file I open gets associated with the project file correctly:

DBG [Processsing Message]                      request="\"textDocument/didOpen\""
DBG New document opened for URI:               uri=file:///Users/khaled/src/khaledh/fusion/src/common/pagetables.nim
DBG ShowMessage                                message="RegEx matched `src/(kernel|common)/.*\\.nim` for file `/Users/khaled/src/khaledh/fusion/src/common/pagetables.nim`"
DBG Document associated with the following projectFile uri=file:///Users/khaled/src/khaledh/fusion/src/common/pagetables.nim projectFile=/Users/khaled/src/khaledh/fusion/src/kernel/main.nim

I looked at the langserver code, but it's not clear to me what might be the issue. I have a feeling it has to do with waiting on the workspace configuration future, which leads to this comment in getWorkspaceConfiguration:

    #this is the root of a lot a problems as there are multiple race conditions here.
    #since most request doenst really rely on the configuration, we can just go ahead and 
    #return a default one until we have the right one. 
    #TODO review and handle project specific confs when received instead of reliying in this func

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions