Skip to content

Commit

Permalink
feat: add language server
Browse files Browse the repository at this point in the history
  • Loading branch information
monotykamary committed Aug 6, 2024
1 parent 3f1b6c5 commit fd0938a
Show file tree
Hide file tree
Showing 23 changed files with 3,717 additions and 1,924 deletions.
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"terminal.integrated.profiles.osx": {
"devboxCompatibleShell": {
"path": "/bin/zsh",
"args": []
}
},
"terminal.integrated.defaultProfile.osx": "devboxCompatibleShell"
}
44 changes: 41 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,44 @@
# Syntax Highlighting for ArangoDB Query Language (AQL)
# Syntax Highlighting and Language Server for ArangoDB Query Language (AQL)

Provides basic syntax highlighting for AQL. This repository was originally inspired and bootstrapped from clintwood's [arango-aql-query](https://github.com/clintwood/arango-aql-query) for Atom Editor and has also taken approaches and formatting from ronsoak's [vsc_redshift_extension](https://github.com/ronsoak/vsc_redshift_extension). ronsoak's [article](https://dev.to/ronsoak/i-built-my-own-vs-code-syntax-highlighter-from-scratch-and-here-s-what-i-learned-1h98) on building a syntax highlighter is also a pleasant read if you are interested in making one for your favorite language.
Provides syntax highlighting and language server features for AQL. This repository was originally inspired and bootstrapped from clintwood's [arango-aql-query](https://github.com/clintwood/arango-aql-query) for Atom Editor and has also taken approaches and formatting from ronsoak's [vsc_redshift_extension](https://github.com/ronsoak/vsc_redshift_extension). ronsoak's [article](https://dev.to/ronsoak/i-built-my-own-vs-code-syntax-highlighter-from-scratch-and-here-s-what-i-learned-1h98) on building a syntax highlighter is also a pleasant read if you are interested in making one for your favorite language.

![aql](aql.png)

The highlighter comes with syntax highlighting for template literals to support Foxx and [arangojs](https://github.com/arangodb/arangojs).

![inline-aql](inline-aql.png)

## Features

- Syntax highlighting for AQL
- Language server with autocompletion for AQL keywords and functions

## Building and Running the Extension

To build and run the extension, follow these steps:

1. Clone the repository:
```
git clone https://github.com/monotykamary/vscode-aql.git
cd vscode-aql
```

2. Install dependencies:
```
npm install
```

3. Compile the extension:
```
npm run compile
```

4. Open the project in Visual Studio Code:
```
code .
```

5. Press F5 to run the extension in a new Extension Development Host window.

## Current Highlighting Support

Expand Down Expand Up @@ -67,4 +98,11 @@ Pattern matched to keyword.operator:
- [ ] Variables (from @, LET, and RETURN)

### Language Features
- [ ] Implement and integrate a [language server](https://code.visualstudio.com/api/language-extensions/language-server-extension-guide) for autocompletion, error-checking, jump-to-definitions, etc... through the [Language Server Protocol (LSP)](https://langserver.org/) for multi-editor support.
- [x] Implement and integrate a [language server](https://code.visualstudio.com/api/language-extensions/language-server-extension-guide) for autocompletion
- [ ] Implement error-checking
- [ ] Implement jump-to-definitions
- [ ] Add more advanced language server features

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.
3 changes: 3 additions & 0 deletions client/out/extension.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ExtensionContext } from 'vscode';
export declare function activate(context: ExtensionContext): void;
export declare function deactivate(): Thenable<void> | undefined;
45 changes: 45 additions & 0 deletions client/out/extension.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/out/extension.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 105 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "aql-language-client",
"description": "AQL Language Client",
"version": "1.0.0",
"author": "Your Name",
"license": "MIT",
"engines": {
"vscode": "^1.75.0"
},
"dependencies": {
"vscode-languageclient": "^8.1.0"
},
"devDependencies": {
"@types/vscode": "^1.75.0",
"@types/node": "^16.11.7"
}
}
60 changes: 60 additions & 0 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import * as path from 'path';
import { workspace, ExtensionContext } from 'vscode';

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

let client: LanguageClient;

export function activate(context: ExtensionContext) {
// The server is implemented in node
const serverModule = context.asAbsolutePath(
path.join('server', 'out', 'server.js')
);
// The debug options for the server
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
const debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] };

// 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: serverModule, transport: TransportKind.ipc },
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: debugOptions
}
};

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

// Create and start the client
client = new LanguageClient(
'aqlLanguageServer',
'AQL Language Server',
serverOptions,
clientOptions
);

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

export function deactivate(): Thenable<void> | undefined {
if (!client) {
return undefined;
}
return client.stop();
}
13 changes: 13 additions & 0 deletions client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2020",
"lib": ["es2020"],
"outDir": "out",
"rootDir": "src",
"sourceMap": true,
"composite": true
},
"include": ["src"],
"exclude": ["node_modules", ".vscode-test"]
}
1 change: 1 addition & 0 deletions client/tsconfig.tsbuildinfo

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions devbox.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"packages": {
"nodejs": "21.3.0",
"yarn": "1.22.19",
"podman": "4.9.3",
"podman-tui": "1.0.0",
"podman-compose": "1.0.6"
"nodejs": "21.3.0"
},
"shell": {
"init_hook": [
"npm install"
],
"scripts": {
"generate": "./from-docker.sh",
"release": ["yarn release", "git push --follow-tags origin master"]
"release": ["npm run release", "git push --follow-tags origin master"]
}
}
}
Loading

0 comments on commit fd0938a

Please sign in to comment.