Skip to content

Commit 139f208

Browse files
committed
langserver: improve docs
1 parent ebdb0a7 commit 139f208

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

cmd/bob/langserver.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package main
22

3-
// Bob support for making langserver (https://langserver.org/) integration easier and better with containers.
3+
// Support for making langserver (https://langserver.org/) integration easier and better with containers.
44

55
import (
66
"context"
@@ -34,7 +34,8 @@ func langserverRunShim(ctx context.Context) error {
3434
return err
3535
}
3636

37-
// workdir is not always the same as process's initial workdir
37+
// workdir is not always the same as process's initial workdir.
38+
// after this, we can resolve the chosen project's details.
3839
if err := os.Chdir(workdir); err != nil {
3940
return err
4041
}
@@ -44,8 +45,7 @@ func langserverRunShim(ctx context.Context) error {
4445
// must use the same path in containers (unless we want to do tricks with symlinks etc.)
4546
mountDir := workdir
4647

47-
// assuming LSP client invoked our "LSP server" (we are just a proxy) with our workdir set
48-
// to the project's root, so we can still resolve which project this LSP is about
48+
// access chosen project's details (so we know which programming language's langserver to start)
4949
bobfile, err := readBobfile()
5050
if err != nil {
5151
return err
@@ -55,7 +55,8 @@ func langserverRunShim(ctx context.Context) error {
5555
return errors.New("need at least one builder")
5656
}
5757

58-
builder := bobfile.Builders[0] // FIXME: this is not correct
58+
// FIXME: this is not correct. could use builder.MountSource to resolve specific one
59+
builder := bobfile.Builders[0]
5960

6061
langserverCmd, err := func() ([]string, error) {
6162
baseImageConf, err := loadNonOptionalBaseImageConf(*bobfile, builder)
@@ -106,11 +107,11 @@ func resolveWorkdirFromLSInvocation() (string, error) {
106107
}
107108

108109
// TODO: read this from Bob's userconfig
109-
wrongWorkdirs := map[string]string{
110+
wrongAndCorrectWds := map[string]string{
110111
"/persist/work": "/home/joonas/work",
111112
}
112113

113-
for wdWrong, wdCorrect := range wrongWorkdirs {
114+
for wdWrong, wdCorrect := range wrongAndCorrectWds {
114115
if strings.HasPrefix(workdirDefault, wdWrong) {
115116
/* given:
116117
wdWrong=/wrong/work
@@ -126,6 +127,6 @@ func resolveWorkdirFromLSInvocation() (string, error) {
126127
}
127128
}
128129

129-
// no corrections had to be made, so workdir was already correct
130+
// no correction had to be made, so workdir was already correct
130131
return workdirDefault, nil
131132
}

docs/language-server-support/README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,34 +56,38 @@ Because traditionally the code editor and the language server is expected to be
5656
computer (or to be more exact with containers: the same namespace), there usually is a difference
5757
in the expectations of default usage behaviour and how you want to use it with Bob. Specifically:
5858

59-
| issue | Traditional approach | Containerized way |
59+
| | Traditional approach | Containerized way |
6060
|-------------------------|---|---|
61-
| Start a language server | An editor starts `gopls` a as child process | We want to start `gopls` inside a container |
62-
| Multiple LS instances? | An editor expects one `gopls` instance can access any Go-based project | Each project (also the language server) is in own container, so it can only access the chosen project's files |
61+
| Start a language server | An editor starts `gopls` as a child process | We want to start `gopls` inside a container |
62+
| Multiple LS instances? | An editor expects one `gopls` instance to be able to access any Go-based project | Each project (also the LS) is in own container, so it can only access the chosen project's files |
6363
| File access | Filesystem from editor's & LS's perspective are the same | Host and container filesystems are separated. We can map host paths (like a given project's files) into a container, but paths can be different from host and container perspectives. |
6464

6565
More about file access: e.g. `/home/joonas/work/turbobob` could get mounted in `/workspace` inside a
6666
dev container (the one you get a shell in with `$ bob dev`). Therefore instead of reusing the same
6767
dev container, a language server gets its own container (still based on the same builder image!) for
68-
the purpose of trying to make the paths look the same. This is also a better approach because you
68+
the purpose of trying to make the paths look the same. This is also a good approach because you
6969
don't want your language server stopping if you exit the dev shell.
7070

7171
To help bridge these differences, Bob has a small shim (`$ bob tools langserver`) that handles
7272
starting an LS in a container with the right parameters. The shim isn't strictly necessary, as you
7373
could just rig the `$ docker run ... some/docker-image gopls` command directly into your editor's
7474
LSP config, but it contains so many project-specific parameters (Docker image & its version to use,
75-
project directory path) that it's easier to use the shim because editors expect one `gopls` langserver
76-
instance to be able to deal with all of your projects. We're swimming a bit against the current here
77-
by making a langserver project-specific. Some could say it's a good feature, because now we can't
78-
get version conflicts if a new langserver doesn't work with an old project anymore. :)
75+
project directory path) that it's easier to use the shim.
76+
77+
Editors expect each LS to be without much config (let alone project-specific config) because
78+
traditionally each LS isn't project-specific - one LS instance deals with all of your Go-based projects.
79+
80+
We're swimming a bit against the current here. I'd still say it's a good tradeoff, because Bob enables
81+
ones host system to contain minimal state, and now we can't get version conflicts if a new langserver
82+
doesn't work with an old project anymore. Now a project specifies its langserver it's compatible with. :)
7983

8084

8185
### Beta quality warning
8286

8387
The LSP support is in beta stage. It is working at least in my test setup and there isn't major hacks
8488
preventing wider use - but I haven't tested it more languages and editors yet.
8589

86-
The following has been tested to work: Bob + Sublime Text + gopls.
90+
The following has been tested to work with Go code: Bob + Sublime Text + gopls.
8791

8892

8993
### Known issues
@@ -92,7 +96,7 @@ Here be dragons - Bob's LSP shim isn't perfect yet:
9296

9397
- Depending on your editor you might be able to only access one project at a time for each given
9498
language (unless you create different "langserver instance" configs for each project in your editor).
95-
At least Sublime Text expects that if one `gopls` instance running, it can use that instance to
99+
At least Sublime Text expects that if one `gopls` instance is running, it can use that instance to
96100
access projects A and B, but the `gopls` is in A's container (assuming that project was opened
97101
first and as a result the langserver was launched) and thus can't access B's files.
98102

@@ -109,7 +113,7 @@ Here be dragons - Bob's LSP shim isn't perfect yet:
109113

110114
We're assuming you're using Sublime Text and Go language, but the overall process is the same for every editor:
111115

112-
- Make sure the editor supports LSP, if not, it might have a plugin
116+
- Make sure the editor supports LSP. If not directly, it might have a plugin
113117

114118
- There usually is per-language configuration to enable LSP by specifying a command the editor runs
115119
to start the LS
32 Bytes
Loading

0 commit comments

Comments
 (0)