-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathhandle_initialize.go
103 lines (92 loc) · 2.6 KB
/
handle_initialize.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package langserver
import (
"context"
"encoding/json"
"os/exec"
"path/filepath"
"github.com/sourcegraph/jsonrpc2"
)
func (h *langHandler) handleInitialize(_ context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) {
if req.Params == nil {
return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams}
}
h.conn = conn
var params InitializeParams
if err := json.Unmarshal(*req.Params, ¶ms); err != nil {
return nil, err
}
// https://microsoft.github.io/language-server-protocol/specification#initialize
// The rootUri of the workspace. Is null if no folder is open.
if params.RootURI != "" {
rootPath, err := fromURI(params.RootURI)
if err != nil {
return nil, err
}
h.rootPath = filepath.Clean(rootPath)
h.addFolder(rootPath)
}
var completion *CompletionProvider
var hasCompletionCommand bool
var hasHoverCommand bool
var hasCodeActionCommand bool
var hasSymbolCommand bool
var hasFormatCommand bool
var hasDefinitionCommand bool
if len(h.commands) > 0 {
hasCodeActionCommand = true
}
if h.provideDefinition {
if _, err = exec.LookPath("ctags"); err == nil {
hasDefinitionCommand = true
}
}
for _, config := range h.configs {
for _, v := range config {
if v.CompletionCommand != "" {
hasCompletionCommand = true
}
if v.HoverCommand != "" {
hasHoverCommand = true
}
if v.SymbolCommand != "" {
hasSymbolCommand = true
}
if v.FormatCommand != "" {
hasFormatCommand = true
}
}
}
if params.InitializationOptions != nil {
hasCompletionCommand = params.InitializationOptions.Completion
hasHoverCommand = params.InitializationOptions.Hover
hasCodeActionCommand = params.InitializationOptions.CodeAction
hasSymbolCommand = params.InitializationOptions.DocumentSymbol
hasFormatCommand = params.InitializationOptions.DocumentFormatting
}
if hasCompletionCommand {
chars := []string{"."}
if len(h.triggerChars) > 0 {
chars = h.triggerChars
}
completion = &CompletionProvider{
TriggerCharacters: chars,
}
}
return InitializeResult{
Capabilities: ServerCapabilities{
TextDocumentSync: TDSKFull,
DocumentFormattingProvider: hasFormatCommand,
DocumentSymbolProvider: hasSymbolCommand,
DefinitionProvider: hasDefinitionCommand,
CompletionProvider: completion,
HoverProvider: hasHoverCommand,
CodeActionProvider: hasCodeActionCommand,
Workspace: &ServerCapabilitiesWorkspace{
WorkspaceFolders: WorkspaceFoldersServerCapabilities{
Supported: true,
ChangeNotifications: true,
},
},
},
}, nil
}