forked from camel-tooling/camel-language-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CamelLanguageServer.java
145 lines (125 loc) · 4.8 KB
/
CamelLanguageServer.java
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.cameltooling.lsp.internal;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import org.eclipse.lsp4j.CodeActionKind;
import org.eclipse.lsp4j.CodeActionOptions;
import org.eclipse.lsp4j.CompletionOptions;
import org.eclipse.lsp4j.InitializeParams;
import org.eclipse.lsp4j.InitializeResult;
import org.eclipse.lsp4j.InitializedParams;
import org.eclipse.lsp4j.MessageParams;
import org.eclipse.lsp4j.MessageType;
import org.eclipse.lsp4j.ServerCapabilities;
import org.eclipse.lsp4j.TextDocumentSyncKind;
import org.eclipse.lsp4j.services.LanguageClient;
import org.eclipse.lsp4j.services.LanguageClientAware;
import org.eclipse.lsp4j.services.LanguageServer;
import org.eclipse.lsp4j.services.WorkspaceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.cameltooling.lsp.internal.settings.SettingsManager;
import com.github.cameltooling.lsp.internal.telemetry.TelemetryManager;
/**
* this is the actual server implementation
*
* @author lhein
*/
public class CamelLanguageServer extends AbstractLanguageServer implements LanguageServer, LanguageClientAware {
public static final String LANGUAGE_ID = "LANGUAGE_ID_APACHE_CAMEL";
private static final Logger LOGGER = LoggerFactory.getLogger(CamelLanguageServer.class);
private LanguageClient client;
private SettingsManager settingsManager;
private TelemetryManager telemetryManager;
public CamelLanguageServer() {
CamelTextDocumentService textDocumentService = new CamelTextDocumentService(this);
setTextDocumentService(textDocumentService);
settingsManager = new SettingsManager(textDocumentService);
setWorkspaceService(new CamelWorkspaceService(getSettingsManager()));
}
@Override
public void connect(LanguageClient client) {
this.client = client;
telemetryManager = new TelemetryManager(client);
}
@Override
public void exit() {
super.stopServer();
System.exit(0);
}
@Override
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
Integer processId = params.getProcessId();
if(processId != null) {
setParentProcessId(processId.longValue());
} else {
LOGGER.info("Missing Parent process ID!!");
setParentProcessId(0);
}
getSettingsManager().apply(params);
ServerCapabilities capabilities = createServerCapabilities();
InitializeResult result = new InitializeResult(capabilities);
return CompletableFuture.completedFuture(result);
}
@Override
public void initialized(InitializedParams params) {
LanguageServer.super.initialized(params);
if(telemetryManager != null) {
telemetryManager.onInitialized();
}
}
private ServerCapabilities createServerCapabilities() {
ServerCapabilities capabilities = new ServerCapabilities();
capabilities.setTextDocumentSync(TextDocumentSyncKind.Full);
capabilities.setCompletionProvider(new CompletionOptions(Boolean.TRUE, Arrays.asList(".","?","&", "\"", "=")));
capabilities.setHoverProvider(Boolean.TRUE);
capabilities.setDocumentSymbolProvider(Boolean.TRUE);
capabilities.setReferencesProvider(Boolean.TRUE);
capabilities.setDefinitionProvider(Boolean.TRUE);
capabilities.setCodeActionProvider(new CodeActionOptions(Arrays.asList(CodeActionKind.QuickFix)));
capabilities.setFoldingRangeProvider(Boolean.TRUE);
return capabilities;
}
@Override
public CompletableFuture<Object> shutdown() {
super.shutdownServer();
return CompletableFuture.completedFuture(new Object());
}
@Override
public WorkspaceService getWorkspaceService() {
return super.getWorkspaceService();
}
/**
* Sends the given <code>show message notification</code> back to the client
* as a notification
*
* @param type
* the type of message
* @param msg
* The message to send back to the client
*/
public void sendShowMessageNotification(final MessageType type, final String msg) {
getClient().showMessage(new MessageParams(type, msg));
}
public LanguageClient getClient() {
return client;
}
public SettingsManager getSettingsManager() {
return settingsManager;
}
}