-
Notifications
You must be signed in to change notification settings - Fork 75
Migrate Vue language server to 3.x #1920
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
Open
zulus
wants to merge
1
commit into
eclipse-wildwebdeveloper:master
Choose a base branch
from
zulus:vue3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+442
−278
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
475 changes: 240 additions & 235 deletions
475
...se.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestLanguageServers.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/jsts/JSTSLanguageServerAPI.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 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 <[email protected]> - initial implementation | ||
*******************************************************************************/ | ||
package org.eclipse.wildwebdeveloper.jsts; | ||
|
||
import org.eclipse.lsp4j.services.LanguageServer; | ||
|
||
public interface JSTSLanguageServerAPI extends LanguageServer { | ||
|
||
public final static String TS_REQUEST_COMMAND = "typescript.tsserverRequest"; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/jsts/request/ExecuteInfo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 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 <[email protected]> - initial implementation | ||
*******************************************************************************/ | ||
package org.eclipse.wildwebdeveloper.jsts.request; | ||
|
||
public class ExecuteInfo { | ||
|
||
private int executionTarget = 0; | ||
|
||
private boolean expectsResult = true; | ||
|
||
private boolean isAsync = false; | ||
|
||
private boolean lowPriority = true; | ||
|
||
public int getExecutionTarget() { | ||
return executionTarget; | ||
} | ||
|
||
public void setExecutionTarget(int executionTarget) { | ||
this.executionTarget = executionTarget; | ||
} | ||
|
||
public boolean isExpectsResult() { | ||
return expectsResult; | ||
} | ||
|
||
public void setExpectsResult(boolean expectsResult) { | ||
this.expectsResult = expectsResult; | ||
} | ||
|
||
public boolean isAsync() { | ||
return isAsync; | ||
} | ||
|
||
public void setAsync(boolean isAsync) { | ||
this.isAsync = isAsync; | ||
} | ||
|
||
public boolean isLowPriority() { | ||
return lowPriority; | ||
} | ||
|
||
public void setLowPriority(boolean lowPriority) { | ||
this.lowPriority = lowPriority; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,34 +16,41 @@ | |
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URL; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.eclipse.core.runtime.FileLocator; | ||
import org.eclipse.core.runtime.ILog; | ||
import org.eclipse.lsp4e.LSPEclipseUtils; | ||
import org.eclipse.lsp4e.LanguageServers; | ||
import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider; | ||
import org.eclipse.lsp4j.ExecuteCommandParams; | ||
import org.eclipse.lsp4j.jsonrpc.messages.Message; | ||
import org.eclipse.lsp4j.jsonrpc.messages.NotificationMessage; | ||
import org.eclipse.lsp4j.services.LanguageServer; | ||
import org.eclipse.wildwebdeveloper.embedder.node.NodeJSManager; | ||
import org.eclipse.wildwebdeveloper.jsts.JSTSLanguageServerAPI; | ||
import org.eclipse.wildwebdeveloper.jsts.request.ExecuteInfo; | ||
|
||
public class VueLanguageServer extends ProcessStreamConnectionProvider { | ||
private static String tsserverPath = null; | ||
private static String vuePath = null; | ||
private static String TS_REQUEST = "tsserver/request"; | ||
|
||
public VueLanguageServer() { | ||
|
||
List<String> commands = new ArrayList<>(); | ||
commands.add(NodeJSManager.getNodeJsLocation().getAbsolutePath()); | ||
try { | ||
if (vuePath == null || tsserverPath == null) { | ||
if (vuePath == null) { | ||
resolvePaths(); | ||
} | ||
commands.add(vuePath); | ||
commands.add("--stdio"); | ||
setCommands(commands); | ||
setWorkingDirectory(System.getProperty("user.dir")); | ||
//setWorkingDirectory(System.getProperty("user.dir")); | ||
} catch (IOException e) { | ||
ILog.get().error(e.getMessage(), e); | ||
} | ||
|
@@ -53,44 +60,56 @@ private void resolvePaths() throws IOException { | |
URL url = FileLocator | ||
.toFileURL(getClass().getResource("/node_modules/@vue/language-server/bin/vue-language-server.js")); | ||
vuePath = new File(url.getPath()).getAbsolutePath(); | ||
|
||
url = FileLocator.toFileURL(getClass().getResource("/node_modules/typescript/lib")); | ||
tsserverPath = new File(url.getPath()).getAbsolutePath(); | ||
|
||
} | ||
|
||
|
||
@Override | ||
protected ProcessBuilder createProcessBuilder() { | ||
ProcessBuilder builder = super.createProcessBuilder(); | ||
builder.environment().put("VUE_NONPOLLING_WATCHER", Boolean.toString(true)); | ||
builder.environment().put("NODE_ENV", "production"); | ||
return builder; | ||
} | ||
|
||
@Override | ||
public Object getInitializationOptions(URI rootUri) { | ||
Map<String, Object> options = new HashMap<>(); | ||
setWorkingDirectory(Paths.get(rootUri).toString()); | ||
|
||
options.put("typescript", Collections.singletonMap("tsdk", tsserverPath)); | ||
options.put("diagnosticModel", 0); | ||
options.put("additionalExtensions", new String[] {}); | ||
|
||
Map<String, Object> legend = new HashMap<>(); | ||
legend.put("tokenTypes", new String[] {"component"} ); | ||
legend.put("tokenModifiers", new String[] {} ); | ||
options.put("semanticTokensLegend", legend); | ||
|
||
Map<String, Object> vue = new HashMap<>(); | ||
vue.put("hybridMode", false); | ||
|
||
options.put("vue", vue); | ||
|
||
return options; | ||
public String toString() { | ||
return "VUE Language Server: " + super.toString(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "VUE Language Server: " + super.toString(); | ||
public void handleMessage(Message message, LanguageServer languageServer, URI rootURI) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If someone have know howto move this to VueClientImpl I'll be happy to do this |
||
if (message instanceof NotificationMessage) { | ||
NotificationMessage msg = (NotificationMessage) message; | ||
if (msg.getMethod().equals(TS_REQUEST)) { | ||
forwardTS((Object[]) msg.getParams(), (VueLanguageServerAPI) languageServer, rootURI); | ||
} | ||
} | ||
super.handleMessage(message, languageServer, rootURI); | ||
} | ||
|
||
@SuppressWarnings("restriction") | ||
private void forwardTS(Object[] params, VueLanguageServerAPI languageServer, URI rootURI) { | ||
Object requestId = params[0]; | ||
String commandId = (String) params[1]; | ||
Object args = params.length > 2 ? params[2] : null; | ||
|
||
LanguageServers.forProject(LSPEclipseUtils.findResourceFor(rootURI).getProject()) | ||
.collectAll((w, ls) -> CompletableFuture.completedFuture(ls)).thenAccept((lss) -> { | ||
lss.stream().filter(JSTSLanguageServerAPI.class::isInstance).map(JSTSLanguageServerAPI.class::cast) | ||
.findAny().ifPresent(jsts -> { | ||
jsts.getWorkspaceService() | ||
.executeCommand(new ExecuteCommandParams(JSTSLanguageServerAPI.TS_REQUEST_COMMAND, | ||
Arrays.asList(new Object[] { commandId, args, new ExecuteInfo() }))) | ||
.whenComplete((result, e) -> { | ||
Object body = null; | ||
if (result instanceof Map) { | ||
body = ((Map<?, ?>)result).get("body"); | ||
} | ||
languageServer.tsserverResponse(new Object[] {requestId, body}); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vue consume same configuration as HTML/CSS LS, so I just copy/paste