Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement lsp4e configuration provider #1356

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 26 additions & 2 deletions org.eclipse.wildwebdeveloper/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -550,14 +550,38 @@
priority="normal">
</content-type>
</extension>

<extension
point="org.eclipse.lsp4e.languageServerConfiguration">
<provider class="org.eclipse.wildwebdeveloper.jsts.ui.preferences.javascript.JSTSConfigurationProvider">

</provider>

<alias source="javascript.inlayHints.includeInlayEnumMemberValueHints" target="javascript.inlayHints.enumMemberValues.enabled" />
<alias source="javascript.inlayHints.includeInlayParameterNameHints" target="javascript.inlayHints.parameterNames.enabled" />
<alias source="javascript.inlayHints.includeInlayParameterNameHintsWhenArgumentMatchesName" target="javascript.inlayHints.parameterNames.suppressWhenArgumentMatchesName" />
<alias source="javascript.inlayHints.includeInlayFunctionParameterTypeHints" target="javascript.inlayHints.parameterTypes.enabled" />
<alias source="javascript.inlayHints.includeInlayVariableTypeHints" target="javascript.inlayHints.variableTypes.enabled" />
<alias source="javascript.inlayHints.includeInlayVariableTypeHintsWhenTypeMatchesName" target="javascript.inlayHints.variableTypes.suppressWhenTypeMatchesName" />
<alias source="javascript.inlayHints.includeInlayPropertyDeclarationTypeHints" target="javascript.inlayHints.propertyDeclarationTypes.enabled" />
<alias source="javascript.inlayHints.includeInlayFunctionLikeReturnTypeHints" target="javascript.inlayHints.functionLikeReturnTypes.enabled" />

<alias source="typescript.inlayHints.includeInlayEnumMemberValueHints" target="typescript.inlayHints.enumMemberValues.enabled" />
<alias source="typescript.inlayHints.includeInlayParameterNameHints" target="typescript.inlayHints.parameterNames.enabled" />
<alias source="typescript.inlayHints.includeInlayParameterNameHintsWhenArgumentMatchesName" target="typescript.inlayHints.parameterNames.suppressWhenArgumentMatchesName" />
<alias source="typescript.inlayHints.includeInlayFunctionParameterTypeHints" target="typescript.inlayHints.parameterTypes.enabled" />
<alias source="typescript.inlayHints.includeInlayVariableTypeHints" target="typescript.inlayHints.variableTypes.enabled" />
<alias source="typescript.inlayHints.includeInlayVariableTypeHintsWhenTypeMatchesName" target="typescript.inlayHints.variableTypes.suppressWhenTypeMatchesName" />
<alias source="typescript.inlayHints.includeInlayPropertyDeclarationTypeHints" target="typescript.inlayHints.propertyDeclarationTypes.enabled" />
<alias source="typescript.inlayHints.includeInlayFunctionLikeReturnTypeHints" target="typescript.inlayHints.functionLikeReturnTypes.enabled" />
</extension>
<extension
point="org.eclipse.lsp4e.languageServer">
<server
class="org.eclipse.wildwebdeveloper.jsts.JSTSLanguageServer"
clientImpl="org.eclipse.wildwebdeveloper.jsts.JSTSLanguageClientImpl"
id="org.eclipse.wildwebdeveloper.jsts"
label="JavaScript-TypeScript Language Server">
label="JavaScript-TypeScript Language Server"
watchConfiguration="javascript,typescript">
</server>
<contentTypeMapping
languageId="javascript"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,16 @@
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.lsp4j.DidChangeConfigurationParams;
import org.eclipse.lsp4j.InitializeResult;
import org.eclipse.lsp4j.jsonrpc.messages.Message;
import org.eclipse.lsp4j.jsonrpc.messages.ResponseMessage;
import org.eclipse.lsp4j.services.LanguageServer;
import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider;
import org.eclipse.wildwebdeveloper.Activator;
import org.eclipse.wildwebdeveloper.embedder.node.NodeJSManager;
import org.eclipse.wildwebdeveloper.jsts.ui.preferences.javascript.JavaScriptPreferenceServerConstants;
import org.eclipse.wildwebdeveloper.jsts.ui.preferences.typescript.TypeScriptPreferenceServerConstants;
import org.eclipse.wildwebdeveloper.ui.preferences.ProcessStreamConnectionProviderWithPreference;

public class JSTSLanguageServer extends ProcessStreamConnectionProviderWithPreference {

private static final String JSTS_LANGUAGE_SERVER_ID = "org.eclipse.wildwebdeveloper.jsts";

private static final String[] SUPPORTED_SECTIONS = { "typescript", "javascript" };
public class JSTSLanguageServer extends ProcessStreamConnectionProvider {

private static String tsserverPath;

public JSTSLanguageServer() {
super(JSTS_LANGUAGE_SERVER_ID, Activator.getDefault().getPreferenceStore(), SUPPORTED_SECTIONS);
super();
List<String> commands = new ArrayList<>();
commands.add(NodeJSManager.getNodeJsLocation().getAbsolutePath());
try {
Expand Down Expand Up @@ -99,24 +88,4 @@ public Object getInitializationOptions(URI rootUri) {
return options;
}

@Override
protected Object createSettings() {
Map<String, Object> settings = new HashMap<>();
// javascript
settings.putAll(JavaScriptPreferenceServerConstants.getGlobalSettings());
// typescript
settings.putAll(TypeScriptPreferenceServerConstants.getGlobalSettings());
return settings;
}

@Override
public void handleMessage(Message message, LanguageServer languageServer, URI rootUri) {
if (message instanceof ResponseMessage responseMessage) {
if (responseMessage.getResult() instanceof InitializeResult) {
// enable validation: so far, no better way found than changing conf after init.
DidChangeConfigurationParams params = new DidChangeConfigurationParams(createSettings());
languageServer.getWorkspaceService().didChangeConfiguration(params);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2023 Dawid Pakuła and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Dawid Pakuła - initial implementation
*******************************************************************************/
package org.eclipse.wildwebdeveloper.jsts.ui.preferences.javascript;

import org.eclipse.lsp4e.configuration.EclipsePreferenceProvider;
import org.eclipse.wildwebdeveloper.Activator;
import org.eclipse.wildwebdeveloper.jsts.ui.preferences.typescript.TypeScriptPreferenceServerConstants;

public class JSTSConfigurationProvider extends EclipsePreferenceProvider {

public JSTSConfigurationProvider() {
super(Activator.PLUGIN_ID);

addBool(JavaScriptPreferenceServerConstants.JAVASCRIPT_PREFERENCES_INLAY_HINTS_INCLUDE_INLAY_ENUM_MEMBER_VALUE_HINTS);
addBool(JavaScriptPreferenceServerConstants.JAVASCRIPT_PREFERENCES_INLAY_HINTS_INCLUDE_INLAY_FUNCTION_LIKE_RETURN_TYPE_HINTS);
addBool(JavaScriptPreferenceServerConstants.JAVASCRIPT_PREFERENCES_INLAY_HINTS_INCLUDE_INLAY_FUNCTION_PARAMETER_TYPE_HINTS);
add(JavaScriptPreferenceServerConstants.JAVASCRIPT_PREFERENCES_INLAY_HINTS_INCLUDE_INLAY_PARAMETER_NAME_HINTS);
addBool(JavaScriptPreferenceServerConstants.JAVASCRIPT_PREFERENCES_INLAY_HINTS_INCLUDE_INLAY_PARAMETER_NAME_HINTS_WHEN_ARGUMENT_MATCHES_NAME);
addBool(JavaScriptPreferenceServerConstants.JAVASCRIPT_PREFERENCES_INLAY_HINTS_INCLUDE_INLAY_PROPERTY_DECLARATION_TYPE_HINTS);
addBool(JavaScriptPreferenceServerConstants.JAVASCRIPT_PREFERENCES_INLAY_HINTS_INCLUDE_INLAY_VARIABLE_TYPE_HINTS_WHEN_TYPE_MATCHES_NAME);

addBool(TypeScriptPreferenceServerConstants.TYPESCRIPT_PREFERENCES_INLAY_HINTS_INCLUDE_INLAY_ENUM_MEMBER_VALUE_HINTS);
addBool(TypeScriptPreferenceServerConstants.TYPESCRIPT_PREFERENCES_INLAY_HINTS_INCLUDE_INLAY_FUNCTION_LIKE_RETURN_TYPE_HINTS);
addBool(TypeScriptPreferenceServerConstants.TYPESCRIPT_PREFERENCES_INLAY_HINTS_INCLUDE_INLAY_FUNCTION_PARAMETER_TYPE_HINTS);
add(TypeScriptPreferenceServerConstants.TYPESCRIPT_PREFERENCES_INLAY_HINTS_INCLUDE_INLAY_PARAMETER_NAME_HINTS);
addBool(TypeScriptPreferenceServerConstants.TYPESCRIPT_PREFERENCES_INLAY_HINTS_INCLUDE_INLAY_PARAMETER_NAME_HINTS_WHEN_ARGUMENT_MATCHES_NAME);
addBool(TypeScriptPreferenceServerConstants.TYPESCRIPT_PREFERENCES_INLAY_HINTS_INCLUDE_INLAY_PROPERTY_DECLARATION_TYPE_HINTS);
addBool(TypeScriptPreferenceServerConstants.TYPESCRIPT_PREFERENCES_INLAY_HINTS_INCLUDE_INLAY_VARIABLE_TYPE_HINTS_WHEN_TYPE_MATCHES_NAME);
}

}