-
Notifications
You must be signed in to change notification settings - Fork 568
/
Copy pathlsp.go
56 lines (48 loc) · 1.47 KB
/
lsp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"errors"
"flag"
"fmt"
"io"
"os"
"github.com/microsoft/typescript-go/internal/bundled"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/lsp"
"github.com/microsoft/typescript-go/internal/pprof"
"github.com/microsoft/typescript-go/internal/vfs/osvfs"
)
func runLSP(args []string) int {
flag := flag.NewFlagSet("lsp", flag.ContinueOnError)
stdio := flag.Bool("stdio", false, "use stdio for communication")
pprofDir := flag.String("pprofDir", "", "Generate pprof CPU/memory profiles to the given directory.")
pipe := flag.String("pipe", "", "use named pipe for communication")
_ = pipe
socket := flag.String("socket", "", "use socket for communication")
_ = socket
if err := flag.Parse(args); err != nil {
return 2
}
if !*stdio {
fmt.Fprintln(os.Stderr, "only stdio is supported")
return 1
}
if *pprofDir != "" {
fmt.Fprintf(os.Stderr, "pprof profiles will be written to: %v\n", *pprofDir)
profileSession := pprof.BeginProfiling(*pprofDir, os.Stderr)
defer profileSession.Stop()
}
fs := bundled.WrapFS(osvfs.FS())
defaultLibraryPath := bundled.LibPath()
s := lsp.NewServer(&lsp.ServerOptions{
In: os.Stdin,
Out: os.Stdout,
Err: os.Stderr,
Cwd: core.Must(os.Getwd()),
FS: fs,
DefaultLibraryPath: defaultLibraryPath,
})
if err := s.Run(); err != nil && !errors.Is(err, io.EOF) {
return 1
}
return 0
}