Skip to content

Commit

Permalink
Merge pull request #32664 from vespa-engine/interns/magnus/servicesxml
Browse files Browse the repository at this point in the history
Interns/magnus/servicesxml
  • Loading branch information
Mangern authored Oct 25, 2024
2 parents b8d2453 + 1b4dbd6 commit 217825f
Show file tree
Hide file tree
Showing 85 changed files with 2,505 additions and 348 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.intellijPlatform/
.run/
build/
bin/
gradle/
gradle.properties
gradlew
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{
"label": "langserver",
"type": "npm",
"script": "langserver-install",
"script": "vscode:prepublish",
"group": {
"kind": "build"
},
Expand Down
5 changes: 5 additions & 0 deletions integration/schema-language-server/clients/vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ The extension requires Java 17 or greater. Upon activation, the extension will l
- User setting: vespaSchemaLS.javaHome
- JDK_HOME environment variable
- JAVA_HOME environment variable

## XML support
This extension bundles with an extension to the [LemMinX XML Language server](https://github.com/eclipse/lemminx).
This is to provide additional support when editing the services.xml file in Vespa applications.
For the best possible experience, install the [VSCode XML extension](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-xml) as well.
18 changes: 13 additions & 5 deletions integration/schema-language-server/clients/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@
"categories": [
"Programming Languages",
"Snippets",
"Other"
"Other"
],
"keywords": [
"Vespa",
"Schema"
],
"repository": {
"type": "git",
"type": "git",
"url": "https://github.com/vespa-engine/vespa"
},
"icon": "images/icon.png",
"activationEvents": [],
"activationEvents": [
"onLanguage:xml",
"onLanguage:vespaSchema"
],
"main": "./dist/extension.js",
"contributes": {
"languages": [
Expand All @@ -33,11 +36,15 @@
],
"extensions": [
".sd",
".profile"
".profile",
".yql"
],
"configuration": "./language-configuration.json"
}
],
"xml.javaExtensions": [
"./server/lemminx-vespa-jar-with-dependencies.jar"
],
"configuration": {
"title": "Vespa Schema Language Support",
"properties": {
Expand Down Expand Up @@ -65,7 +72,8 @@
"test": "vscode-test",
"check-types": "tsc --noEmit",
"copy-images": "cp ../../resources/* ./images",
"langserver-install": "mkdir -p server && cp ../../language-server/target/schema-language-server-jar-with-dependencies.jar ./server/",
"langserver-install": "mkdir -p server && cp ../../language-server/target/schema-language-server-jar-with-dependencies.jar ./server/ && npm run lemminx-install",
"lemminx-install": "mkdir -p server && cp ../../lemminx-vespa/target/lemminx-vespa-jar-with-dependencies.jar ./server/",
"publish": "npm run compile && node out/publish.js"
},
"devDependencies": {
Expand Down
86 changes: 73 additions & 13 deletions integration/schema-language-server/clients/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import * as vscode from 'vscode';
import fs from 'fs';
import hasbin from 'hasbin';

import { LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient/node';
import { ExecuteCommandParams, ExecuteCommandRequest, LanguageClient, LanguageClientOptions, ProtocolRequestType, RequestType, ServerOptions, ExecuteCommandRegistrationOptions } from 'vscode-languageclient/node';

let client: LanguageClient | null = null;
let schemaClient: LanguageClient | null = null;

const JAVA_HOME_SETTING = 'vespaSchemaLS.javaHome';
const EXTENSION_NAME = 'vespaSchemaLS';
const JAVA_HOME_SETTING = 'javaHome';
const RECOMMEND_XML_SETTING = 'recommendXML';
// update if something changes
const JAVA_DOWNLOAD_URL = 'https://www.oracle.com/java/technologies/downloads/#java17';


type maybeString = string|null|undefined;

function javaExecutableExists(javaHome: maybeString) {
Expand All @@ -22,7 +25,7 @@ function javaExecutableExists(javaHome: maybeString) {

function findJavaHomeExecutable(): maybeString {
// Try workspace setting first
const config = vscode.workspace.getConfiguration();
const config = vscode.workspace.getConfiguration(EXTENSION_NAME);
const javaHome = config.get(JAVA_HOME_SETTING) as maybeString;
if (javaExecutableExists(javaHome)) {
return path.join(javaHome as string, 'bin', 'java');
Expand Down Expand Up @@ -92,7 +95,10 @@ function createAndStartClient(serverPath: string): LanguageClient | null {
}
};
const client = new LanguageClient('vespaSchemaLS', 'Vespa Schema Language Server', serverOptions, clientOptions);
client.start();

client.start().then(result => {
console.log(result);
});
return client;
}

Expand All @@ -118,25 +124,79 @@ function showJavaErrorMessage() {
}

export function activate(context: vscode.ExtensionContext) {

checkForXMLExtension();

const jarPath = path.join(__dirname, '..', 'server', 'schema-language-server-jar-with-dependencies.jar');

client = createAndStartClient(jarPath);
schemaClient = createAndStartClient(jarPath);

const logger = vscode.window.createOutputChannel("Vespa language client", {log: true});

context.subscriptions.push(vscode.commands.registerCommand("vespaSchemaLS.restart", (() => {
if (client === null) {
client = createAndStartClient(jarPath);
} else if (client.isRunning()) {
client.restart();
if (schemaClient === null) {
schemaClient = createAndStartClient(jarPath);
} else if (schemaClient.isRunning()) {
schemaClient.restart();
} else {
client.start();
schemaClient.start();
}
})));


context.subscriptions.push(vscode.commands.registerCommand("vespaSchemaLS.servicesxml.findDocument", async (fileName) => {
if (schemaClient !== null) {
try {
const result = await schemaClient.sendRequest("workspace/executeCommand", {
command: "FIND_SCHEMA_DEFINITION",
arguments: [fileName]
});
return result;
} catch (err) {
logger.error("Error when sending command: ", err);
}
}
return null;
}));

// This command exists to setup schema language server workspace in case the first opened document is an xml file (which not handled by schema language server)
context.subscriptions.push(vscode.commands.registerCommand("vespaSchemaLS.servicesxml.setupWorkspace", async (fileURI) => {
if (schemaClient !== null) {
try {
schemaClient.sendRequest("workspace/executeCommand", {
command: "SETUP_WORKSPACE",
arguments: [fileURI]
});
} catch (err) {
logger.error("Error when trying to send setup workspace command: ", err);
}
}
}));

logger.info("Vespa language client activated");
}


export function deactivate() {
if (!client) {
if (!schemaClient) {
return undefined;
}
return client.stop();
return schemaClient.stop();
}

async function checkForXMLExtension() {
const xmlExtensionName = "redhat.vscode-xml";

const xmlExtension = vscode.extensions.getExtension(xmlExtensionName);

if (!xmlExtension && vscode.workspace.getConfiguration(EXTENSION_NAME).get(RECOMMEND_XML_SETTING, true)) {
const message = "It is recommended to install the Red Hat XML extension in order to get support when writing the services.xml file. Do you want to install it now?";
const choice = await vscode.window.showInformationMessage(message, "Install", "Not now", "Do not show again");
if (choice === "Install") {
await vscode.commands.executeCommand("extension.open", xmlExtensionName);
await vscode.commands.executeCommand("workbench.extensions.installExtension", xmlExtensionName);
} else if (choice === "Do not show again") {
vscode.workspace.getConfiguration(EXTENSION_NAME).set(RECOMMEND_XML_SETTING, false);
}
}
}
17 changes: 13 additions & 4 deletions integration/schema-language-server/language-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,17 @@
<jdk>17</jdk>
</configuration>
</execution>
<execution>
<id>4</id>
<goals>
<goal>ccc-generate</goal>
</goals>
<configuration>
<grammarFile>${project.basedir}/src/main/ccc/yqlplus/YQLPlus.ccc</grammarFile>
<outputDir>${project.basedir}/target/generated-sources/ccc</outputDir>
<jdk>17</jdk>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand All @@ -197,7 +208,8 @@
<excludePackageNames>
ai.vespa.schemals.parser,
ai.vespa.schemals.parser.indexinglanguage,
ai.vespa.schemals.parser.rankingexpression
ai.vespa.schemals.parser.rankingexpression,
ai.vespa.schemals.parser.yqlplus
</excludePackageNames>
</configuration>
</plugin>
Expand All @@ -214,9 +226,6 @@
<configuration>
<sources>
<source>${project.basedir}/target/generated-sources/ccc</source>
<source>${project.parent.basedir}/../config-model/target/generated-sources/javacc</source>
<source>${project.parent.basedir}/../indexinglanguage/target/generated-sources/javacc</source>
<source>${project.parent.basedir}/../searchlib/target/generated-sources/javacc</source>
</sources>
</configuration>
</execution>
Expand Down
Loading

0 comments on commit 217825f

Please sign in to comment.