Search code examples
visual-studio-codelanguage-server-protocol

how can a language server access a file in the same directory as the source file


I am writing a language server for my custom language. The way a source file is processed is partly influenced by a manifest.json file in the same directory as the source file. In a workspace there might be multiple directories with multiple source files and 1 manifest file per directory. example

DirA
    manifest.json
    sourcefile1.xyz
    sourcefile2.xyz
DirB
    DirB1
        manifest.json
        sf3.xyz
    DirB2
        manifest.json
        sf4.xyz

How can I make the manifest.json file available to the language server when the user is editing a .xyz file.


Solution

  • the language server receives a TextDocument class which contains a uri. This uri has the 'file' protocol if it is stored on disk. with path.dirname(uri), you can get the directory of the file.