Skip to content

Commit

Permalink
tried many variations of the vanilla vscode language setup, till I go…
Browse files Browse the repository at this point in the history
…t the basic tests working...
  • Loading branch information
cblanquera committed Jun 29, 2024
1 parent 0fcb886 commit 987fbcd
Show file tree
Hide file tree
Showing 247 changed files with 1,925 additions and 2,662 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,5 @@ dist

archives
.temple
.DS_Store
.DS_Store
.build
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions env/temple-language/client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "temple-language-client",
"description": "Adds syntax highlighting, formatting, auto-completion, jump-to-definition and linting for a custom.",
"version": "0.0.13",
"license": "MIT",
"scripts": {
"build": "tsc"
},
"dependencies": {
"vscode-languageclient": "9.0.1"
}
}
28 changes: 28 additions & 0 deletions env/temple-language/client/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { ExtensionContext } from './language/LanguageClient';

import path from 'path';
import LanguageClient, { useBasic } from './language/LanguageClient';

let client: LanguageClient;

export function activate(context: ExtensionContext) {
// The server is implemented in node
const server = context.asAbsolutePath(path.join('server', 'out', 'index.js'));

client = useBasic({
id: 'languageServerExample',
label: 'Language Server Example',
language: 'plaintext',
server: server
});

// Start the client. This will also launch the server
client.activate();
}

export function deactivate() {
if (!client) {
return undefined;
}
return client.deactivate();
}
95 changes: 95 additions & 0 deletions env/temple-language/client/src/language/LanguageClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
export type { ExtensionContext } from 'vscode';
export type ClientOptions = {
id: string,
label: string,
server: string,
language: string,
scheme?: string,
watcher?: string
};

import { workspace } from 'vscode';
import {
LanguageClient as VSLanguageClient,
LanguageClientOptions,
ServerOptions,
TransportKind
} from 'vscode-languageclient/node';

export default class LanguageClient {
// The vscode language client
protected _client: VSLanguageClient;

/**
* Makes a new vscode language client
*/
constructor(
id: string,
label: string,
serverOptions: ServerOptions,
clientOptions: LanguageClientOptions
) {
// Create the language client and start the client.
this._client = new VSLanguageClient(
id,
label,
serverOptions,
clientOptions
);
}

/**
* Starts the client
*/
activate() {
// Start the client. This will also launch the server
return this._client.start();
}

/**
* Stops the client
*/
deactivate(): Thenable<void> | undefined {
return this._client.stop();
}
}

export function useBasic(options: ClientOptions) {
const {
id,
label,
server,
language,
scheme = 'file',
watcher = '**/.clientrc'
} = options;

// If the extension is launched in debug mode
// then the debug server options are used
// Otherwise the run options are used
const serverOptions: ServerOptions = {
run: { module: server, transport: TransportKind.ipc },
debug: {
module: server,
transport: TransportKind.ipc,
}
};

// Options to control the language client
const clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: [{ scheme, language }],
synchronize: {
// Notify the server about file changes to
// '.clientrc files contained in the workspace
fileEvents: workspace.createFileSystemWatcher(watcher)
}
};

return new LanguageClient(
id,
label,
serverOptions,
clientOptions
);
}
14 changes: 14 additions & 0 deletions env/temple-language/client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"esModuleInterop": true,
"module": "commonjs",
"target": "es2020",
"lib": ["es2020"],
"outDir": "out",
"rootDir": "src",
"sourceMap": true,
"types": []
},
"include": ["src"],
"exclude": ["node_modules"]
}
Loading

0 comments on commit 987fbcd

Please sign in to comment.