Skip to content
This repository was archived by the owner on May 4, 2026. It is now read-only.

Commit 259804d

Browse files
committed
feat: credo lsp
1 parent 2d17feb commit 259804d

3 files changed

Lines changed: 50 additions & 100 deletions

File tree

README.md

Lines changed: 6 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,9 @@
1-
# elixir-tools.vscode README
1+
# elixir-tools.vscode
22

3-
This is the README for your extension "elixir-tools.vsocde". After writing up a brief description, we recommend including the following sections.
3+
The official [elixir-tools](https://github.com/elixir-tools) extension for VSCode!
44

5-
## Features
5+
elixir-tools.vscode provides support for:
66

7-
Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file.
8-
9-
For example if there is an image subfolder under your extension project workspace:
10-
11-
\!\[feature X\]\(images/feature-x.png\)
12-
13-
> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow.
14-
15-
## Requirements
16-
17-
If you have any requirements or dependencies, add a section describing those and how to install and configure them.
18-
19-
## Extension Settings
20-
21-
Include if your extension adds any VS Code settings through the `contributes.configuration` extension point.
22-
23-
For example:
24-
25-
This extension contributes the following settings:
26-
27-
* `myExtension.enable`: Enable/disable this extension.
28-
* `myExtension.thing`: Set to `blah` to do something.
29-
30-
## Known Issues
31-
32-
Calling out known issues can help limit users opening duplicate issues against your extension.
33-
34-
## Release Notes
35-
36-
Users appreciate release notes as you update your extension.
37-
38-
### 1.0.0
39-
40-
Initial release of ...
41-
42-
### 1.0.1
43-
44-
Fixed issue #.
45-
46-
### 1.1.0
47-
48-
Added features X, Y, and Z.
49-
50-
---
51-
52-
## Following extension guidelines
53-
54-
Ensure that you've read through the extensions guidelines and follow the best practices for creating your extension.
55-
56-
* [Extension Guidelines](https://code.visualstudio.com/api/references/extension-guidelines)
57-
58-
## Working with Markdown
59-
60-
You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:
61-
62-
* Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux).
63-
* Toggle preview (`Shift+Cmd+V` on macOS or `Shift+Ctrl+V` on Windows and Linux).
64-
* Press `Ctrl+Space` (Windows, Linux, macOS) to see a list of Markdown snippets.
65-
66-
## For more information
67-
68-
* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
69-
* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)
70-
71-
**Enjoy!**
7+
* Filetype detection for .ex and .exs Elixir files
8+
* Syntax highlight for Elixir
9+
* Credo Language Server

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
"activationEvents": [],
1313
"main": "./dist/extension.js",
1414
"contributes": {
15+
"configuration": {
16+
"title": "elixir-tools",
17+
"properties": {
18+
"elixir-tools.credo.enabled": {
19+
"type": "boolean",
20+
"default": true,
21+
"description": "Whether to start the Credo Language Server."
22+
}
23+
}
24+
},
1525
"languages": [
1626
{
1727
"id": "elixir",

src/extension.ts

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,48 @@
1-
// The module 'vscode' contains the VS Code extensibility API
2-
// Import the module and reference it with the alias vscode in your code below
31
import * as vscode from "vscode";
4-
// import { workspace } from "vscode";
52

63
import {
74
Executable,
85
LanguageClient,
96
LanguageClientOptions,
107
} from "vscode-languageclient/node";
118

12-
let client: LanguageClient;
13-
14-
// This method is called when your extension is activated
15-
// Your extension is activated the very first time the command is executed
16-
export function activate(_context: vscode.ExtensionContext) {
17-
// Options to control the language client
18-
//
19-
const serverOptions: Executable = {
20-
command: "mix",
21-
args: ["credo.lsp", "--stdio"],
22-
};
23-
const clientOptions: LanguageClientOptions = {
24-
// Register the server for plain text documents
25-
documentSelector: [{ scheme: "file", language: "elixir" }],
26-
};
27-
28-
// Create the language client and start the client.
29-
client = new LanguageClient(
30-
"elixir-tools.credo",
31-
"Credo",
32-
serverOptions,
33-
clientOptions
34-
);
35-
36-
// Start the client. This will also launch the server
37-
client.start();
9+
let credoClient: LanguageClient;
10+
11+
export async function activate(_context: vscode.ExtensionContext) {
12+
let files = await vscode.workspace.findFiles("mix.exs");
13+
14+
let config = vscode.workspace.getConfiguration("elixir-tools.credo");
15+
16+
if (files[0]) {
17+
let text = await vscode.workspace.fs.readFile(files[0]);
18+
19+
if (text.toString().includes("{:credo")) {
20+
if (config.get("enabled")) {
21+
const serverOptions: Executable = {
22+
command: "mix",
23+
args: ["credo.lsp", "--stdio"],
24+
};
25+
const clientOptions: LanguageClientOptions = {
26+
documentSelector: [{ scheme: "file", language: "elixir" }],
27+
};
28+
29+
credoClient = new LanguageClient(
30+
"elixir-tools.credo",
31+
"Credo",
32+
serverOptions,
33+
clientOptions
34+
);
35+
36+
// Start the credoClient. This will also launch the server
37+
credoClient.start();
38+
}
39+
}
40+
}
3841
}
3942

40-
// This method is called when your extension is deactivated
4143
export function deactivate() {
42-
if (!client) {
44+
if (!credoClient) {
4345
return undefined;
4446
}
45-
return client.stop();
47+
return credoClient.stop();
4648
}

0 commit comments

Comments
 (0)