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

Upgrade JS dependencies #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
name: run tests for python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4.5.0
- uses: actions/setup-python@v4.7.0
with:
python-version: ${{ matrix.python-version }}

- uses: Gr1N/setup-poetry@v8
- uses: actions/cache@v3.2.3
- uses: actions/cache@v3.3.1
with:
path: ~/.cache/pypoetry/virtualenvs
key: poetry-${{ hashFiles('poetry.lock') }}
Expand Down Expand Up @@ -56,10 +56,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4.5.0
- uses: actions/setup-python@v4.7.0

- uses: Gr1N/setup-poetry@v8
- uses: actions/cache@v3.2.3
- uses: actions/cache@v3.3.3
with:
path: ~/.cache/pypoetry/virtualenvs
key: poetry-${{ hashFiles('poetry.lock') }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/vscode_extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [14.x, 16.x]
node-version: [20.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3.6.0
uses: actions/setup-node@v3.7.0
with:
node-version: ${{ matrix.node-version }}

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v3.2.3
- uses: actions/cache@v3.3.1
with:
path: |
${{ steps.yarn-cache-dir-path.outputs.dir }}
Expand Down
145 changes: 75 additions & 70 deletions clients/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,26 @@
* limitations under the License.
* ----------------------------------------------------------------------- */

import { spawn } from "child_process";
import {spawn} from "child_process";
import * as net from "net";
import { ExtensionContext, window, workspace } from "vscode";
import {ExtensionContext, window, workspace, commands} from "vscode";
import {
LanguageClient,
LanguageClientOptions,
ServerOptions,
Disposable,
} from "vscode-languageclient/node";

class ProcessError extends Error {
constructor(
public readonly command: string,
public readonly returnCode: number | null,
public readonly stdout: any[],
public readonly stderr: any[]
) {
super(
`${command} failed with code=${
returnCode ?? "null"
}, stdout='${stdout.join("\n")}', stderr='${stderr.join("\n")}'`
);
constructor(public readonly command: string, public readonly returnCode: number|null,
public readonly stdout: any[], public readonly stderr: any[]) {
super(`${command} failed with code=${
returnCode ??
"null"}, stdout='${stdout.join("\n")}', stderr='${stderr.join("\n")}'`);
}
}

export function runProcess(
command: string,
args?: readonly string[]
): Promise<string> {
export function runProcess(command: string, args?: readonly string[]): Promise<string> {
return new Promise((resolve, reject) => {
const child = spawn(command, args);

Expand All @@ -60,28 +52,24 @@ export function runProcess(
}
});

child.on("error", (err) => {
reject(err);
});
child.on("error", (err) => { reject(err); });
});
}

let client: LanguageClient;

function getClientOptions(): LanguageClientOptions {
return {
// Register the server for sls files
documentSelector: [
{ scheme: "file", language: "sls" },
{ scheme: "untitled", language: "sls" },
// Register the server for sls files
documentSelector : [
{scheme : "file", language : "sls"},
{scheme : "untitled", language : "sls"},
],
outputChannelName: "[salt_lsp] SaltStateLanguageServer",
outputChannelName : "[salt_lsp] SaltStateLanguageServer",
};
}

function isStartedInDebugMode(): boolean {
return process.env.VSCODE_DEBUG_MODE === "true";
}
function isStartedInDebugMode(): boolean { return process.env.VSCODE_DEBUG_MODE === "true"; }

let clientSocket: net.Socket;

Expand All @@ -92,24 +80,17 @@ function startLangServerTCP(addr: number): LanguageClient {

clientSocket.connect(addr, "127.0.0.1", () => {
resolve({
reader: clientSocket,
writer: clientSocket,
reader : clientSocket,
writer : clientSocket,
});
});

clientSocket.on("close", () => {
setTimeout(() => {
clientSocket.connect(addr, "127.0.0.1");
}, 1000);
});
clientSocket.on(
"close", () => { setTimeout(() => { clientSocket.connect(addr, "127.0.0.1"); }, 1000); });
});
};

return new LanguageClient(
`tcp lang server (port ${addr})`,
serverOptions,
getClientOptions()
);
return new LanguageClient(`tcp lang server (port ${addr})`, serverOptions, getClientOptions());
}

function startLangServer(command: string, args: string[]): LanguageClient {
Expand All @@ -121,45 +102,69 @@ function startLangServer(command: string, args: string[]): LanguageClient {
return new LanguageClient(command, serverOptions, getClientOptions());
}

export async function activate(context: ExtensionContext): Promise<void> {
if (isStartedInDebugMode()) {
client = startLangServerTCP(2087);
} else {
const pythonPath = workspace
.getConfiguration("python")
.get<string>("pythonPath");

if (pythonPath === undefined) {
export async function activate(context: ExtensionContext){
let disposableClient: Disposable;
const startLSPServer = async () => {
if (isStartedInDebugMode()) {
client = startLangServerTCP(2087);
} else {
const pythonPath = workspace
.getConfiguration("python")
.get<string>("pythonPath");

if (pythonPath === undefined) {
try {
await runProcess("python3", ["--version"]);
} catch {
const errMsg =
"'python.pythonPath' not set and could not launch python. Please install python to be able to use this Language Server";
await window.showErrorMessage(errMsg);
throw new Error(errMsg);
}
}

const python = pythonPath ?? "python3";

try {
await runProcess("python3", ["--version"]);
} catch {
const errMsg =
"'python.pythonPath' not set and could not launch python. Please install python to be able to use this Language Server";
await runProcess(python, ["-m", "salt_lsp", "--stop-after-init"]);
} catch (exc) {
const errMsg = `Could not launch the Salt Language Server, got the following error: ${(
exc as ProcessError
).toString()}.

You might have to install salt_lsp via 'pip install salt_lsp'.`;
await window.showErrorMessage(errMsg);
throw new Error(errMsg);
}
}

const python = pythonPath ?? "python3";

try {
await runProcess(python, ["-m", "salt_lsp", "--stop-after-init"]);
} catch (exc) {
const errMsg = `Could not launch the Salt Language Server, got the following error: ${(
exc as ProcessError
).toString()}.

You might have to install salt_lsp via 'pip install salt_lsp'.`;
await window.showErrorMessage(errMsg);
throw new Error(errMsg);
client = startLangServer(python, ["-m", "salt_lsp"]);
}
disposableClient = client
}

client = startLangServer(python, ["-m", "salt_lsp"]);
const restartLanguageServer = function (): Promise<void> {
return new Promise((resolve) => {
if (disposableClient) {
client.stop().then(() => {
disposableClient.dispose();
startLSPServer();
resolve();
});
} else {
startLSPServer();
resolve();
}
});
}

context.subscriptions.push(client.start());
var disposableRestart = commands.registerCommand('salt-lsp.restart', () => {
restartLanguageServer().then(() => {
window.showInformationMessage('Salt-lsp server restarted.');
});
});
context.subscriptions.push(disposableRestart);
await startLSPServer()
}

export function deactivate(): Thenable<void> {
return client ? client.stop() : Promise.resolve();
}
export function deactivate(): Thenable<void> { return client ? client.stop() : Promise.resolve(); }
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@
"package": "vsce package --yarn"
},
"devDependencies": {
"@types/node": "^18",
"typescript": "^4",
"vsce": "^2",
"vscode": "^1.1.36"
"@types/node": "^20",
"@types/vscode": "^1",
"@vscode/test-electron": "^1",
"typescript": "^5",
"vsce": "^2"
},
"dependencies": {
"vscode-languageclient": "^7"
"vscode-languageclient": "^8"
}
}
Loading
Loading