Skip to content

Project root selection

Ruslan Prokopchuk edited this page Mar 25, 2019 · 3 revisions

As the main way to select project root kak-lsp allows the specification of a set of markers per filetype for the project root. On encountering a new buffer we walk from the buffer towards the filesystem root checking at each directory if we have a match for a marker. We stop at the first marker. This works well for build systems with a single root file but not that well for systems that may scatter their build files all over the project directory (in some extreme cases in every folder c.f. tup).

There is an additional way to specify project root using environment variables. For maximum flexibility the following scheme is used: on new buffer detect filetype, and look for all environment variables prefixed with KAK_LSP_PROJECT_ROOT_%FILETYPE%* and add the value of each to a set of roots and proceed as before, the first match wins. This will allow for both regular repos and monorepos browsed from the root to specify subprojects accurately. Consider the following tree:

~/src
├── bar
│   ├── build.sbt
│   └── ext
│       ├── sub1
│       │   ├── build.sbt
│       │   └── src
│       │       └── main
│       │           └── scala
│       └── sub2
│           ├── build.sbt
│           └── src
│               └── main
│                   └── scala
└── foo
    ├── build.sbt
    └── ext
        ├── sub1
        │   ├── build.sbt
        │   └── src
        │       └── main
        │           └── scala
        └── sub2
            ├── build.sbt
            └── src
                └── main
                    └── scala

Then an environment with KAK_LSP_PROJECT_ROOT_SCALA_FOO="$HOME/src/foo" and KAK_LSP_PROJECT_ROOT_SCALA_BAR="$HOME/src/bar" would allow both sets of files to successfully be associated with the correct build. Of course, users that only browse from single sources will be catered too as well and need not suffix at all. Note that the FOO and BAR suffixes are arbitrary and have no meaning when it comes to matching.