Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion org.eclipse.wildwebdeveloper/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -769,14 +769,15 @@
base-type="org.eclipse.wildwebdeveloper.parent"
file-extensions="vue"
id="org.eclipse.wildwebdeveloper.vue"
name="VUE module"
name="VUE component"
priority="normal">
</content-type>
</extension>
<extension point="org.eclipse.lsp4e.languageServer">
<server
class="org.eclipse.wildwebdeveloper.vue.VueLanguageServer"
clientImpl="org.eclipse.wildwebdeveloper.vue.VueClientImpl"
serverInterface="org.eclipse.wildwebdeveloper.vue.VueLanguageServerAPI"
id="org.eclipse.wildwebdeveloper.vue"
label="VUE Language Server"/>
<contentTypeMapping contentType="org.eclipse.wildwebdeveloper.vue" id="org.eclipse.wildwebdeveloper.vue"/>
Expand Down Expand Up @@ -819,6 +820,14 @@
</languageConfiguration>

</extension>

<extension
point="org.eclipse.ui.genericeditor.reconcilers">
<reconciler
class="org.eclipse.wildwebdeveloper.vue.autoinsert.VueAutoInsertReconciler"
contentType="org.eclipse.wildwebdeveloper.vue">
</reconciler>
</extension>

<!-- YAML Language -->
<extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IStatus;
Expand All @@ -28,16 +30,18 @@
import org.eclipse.wildwebdeveloper.embedder.node.NodeJSManager;

public class VueLanguageServer extends ProcessStreamConnectionProvider {

private static String tsserverPath = null;
private static String vuePath = null;

public VueLanguageServer() {

List<String> commands = new ArrayList<>();
commands.add(NodeJSManager.getNodeJsLocation().getAbsolutePath());
try {
URL url = FileLocator
.toFileURL(getClass().getResource("/node_modules/@vue/language-server/bin/vue-language-server.js"));
commands.add(new java.io.File(url.getPath()).getAbsolutePath());
if (vuePath == null || tsserverPath == null) {
resolvePaths();
}
commands.add(vuePath);
commands.add("--stdio");
setCommands(commands);
setWorkingDirectory(System.getProperty("user.dir"));
Expand All @@ -47,6 +51,15 @@ public VueLanguageServer() {
}
}

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();
Expand All @@ -56,15 +69,21 @@ protected ProcessBuilder createProcessBuilder() {

@Override
public Object getInitializationOptions(URI rootUri) {

try {
URL url = FileLocator.toFileURL(getClass().getResource("/node_modules/typescript/lib"));
return Collections.singletonMap("typescript", Collections.singletonMap("tsdk", new File(url.getPath()).getAbsolutePath()));
} catch (IOException e) {
Activator.getDefault().getLog().log(
new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), e.getMessage(), e));
}
return null;
Map<String, Object> options = new HashMap<>();
setWorkingDirectory(rootUri.getRawPath());

options.put("typescript", Collections.singletonMap("tsdk", tsserverPath));
options.put("fullCompletionList", false);
options.put("serverMode", 0);
options.put("diagnosticModel", 1);
options.put("additionalExtensions", new String[] {});

Map<String, Object> legend = new HashMap<>();
legend.put("tokenTypes", new String[] {"compontent"} );
legend.put("tokenModifiers", new String[] {} );
options.put("semanticTokensLegend", legend);

return options;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* 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.vue;

import java.util.concurrent.CompletableFuture;

import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;
import org.eclipse.lsp4j.services.LanguageServer;
import org.eclipse.wildwebdeveloper.vue.autoinsert.AutoInsertParams;
import org.eclipse.wildwebdeveloper.vue.autoinsert.AutoInsertResponse;

/**
* VUE language server API which defines custom LSP commands.
*
*/
public interface VueLanguageServerAPI extends LanguageServer {

/**
* Auto insert custom LSP command provided by the HTML language server to
* support auto close tag and auto insert of quote for attribute.
*
* @param params auto insert parameters.
* @return the content with the auto close tag / auto insert of quote and null
* otherwise.
*
*/
@JsonRequest("volar/client/autoInsert")
CompletableFuture<Either<String, AutoInsertResponse>> autoInsert(AutoInsertParams params);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* 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.vue.autoinsert;

import org.eclipse.lsp4j.TextDocumentContentChangeEvent;

/**
* VUE Auto Insert parameters.
*
*/
public class AutoInsertLastChange extends TextDocumentContentChangeEvent {

private int rangeOffset;

public int getRangeOffset() {
return rangeOffset;
}

public void setRangeOffset(int rangeOffset) {
this.rangeOffset = rangeOffset;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* 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.vue.autoinsert;

public class AutoInsertOptions {

private AutoInsertLastChange lastChange;

public AutoInsertLastChange getLastChange() {
return lastChange;
}

public void setLastChange(AutoInsertLastChange lastChange) {
this.lastChange = lastChange;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*******************************************************************************
* 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.vue.autoinsert;

import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.TextDocumentIdentifier;

/**
* VUE Auto Insert parameters.
*
*/
public class AutoInsertParams {

/**
* The text document.
*/
private TextDocumentIdentifier textDocument;
/**
* The position inside the text document.
*/
private Position position;

private AutoInsertOptions options;


public TextDocumentIdentifier getTextDocument() {
return textDocument;
}

public void setTextDocument(TextDocumentIdentifier textDocument) {
this.textDocument = textDocument;
}

public Position getPosition() {
return position;
}

public void setPosition(Position position) {
this.position = position;
}

public AutoInsertOptions getOptions() {
return options;
}

public void setOptions(AutoInsertOptions options) {
this.options = options;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*******************************************************************************
* 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.vue.autoinsert;

import org.eclipse.lsp4j.Range;

/**
* VUE Auto Insert parameters.
*
*/
public class AutoInsertResponse {

private String newText;

private Range range;

public String getNewText() {
return newText;
}

public void setNewText(String newText) {
this.newText = newText;
}

public Range getRange() {
return range;
}

public void setRange(Range range) {
this.range = range;
}

}
Loading