Skip to content

Support using a different harper-ls executable than the one bundled in the VSCode extension #330

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

Merged
merged 2 commits into from
Dec 26, 2024
Merged
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
1 change: 1 addition & 0 deletions packages/vscode-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Linting Python, Shellscript/Bash, and Git Commit files now work properly.
- Add support for Nix and Plaintext files.
- Add the `harper-ls.path` setting to optionally use a different `harper-ls` executable.

## 0.12.0

Expand Down
9 changes: 5 additions & 4 deletions packages/vscode-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ If you use OpenVSX, for instance if you use VSCodium, you'll want to install fro

### Settings

| Setting | Possible Values | Default Value | Description |
| ------------------------------ | ------------------------------------------------- | --------------- | ----------------------------------------------------------------- |
| `harper-ls.linters.*` | `true`, `false` | Varies | Detect and provide suggestions in a variety of common situations. |
| `harper-ls.diagnosticSeverity` | `"error"`, `"hint"`, `"information"`, `"warning"` | `"information"` | How severe do you want diagnostics to appear in the editor? |
| Setting | Type | Default Value | Description |
| ------------------------------ | ------------------------------------------------- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `harper-ls.path` | `string` | `""` | Optional path to a `harper-ls` executable to use. Primarily useful if the bundled binary doesn't work in your system like in immutable Linux distributions. |
| `harper-ls.linters.*` | `boolean` | Varies | Detect and provide suggestions in a variety of common situations. |
| `harper-ls.diagnosticSeverity` | `"error"`, `"hint"`, `"information"`, `"warning"` | `"information"` | How severe do you want diagnostics to appear in the editor? |

## Developing and Contributing

Expand Down
5 changes: 5 additions & 0 deletions packages/vscode-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
"type": "object",
"title": "Harper",
"properties": {
"harper-ls.path": {
"scope": "resource",
"type": "string",
"description": "Optional path to a harper-ls executable to use."
},
"harper-ls.linters.spell_check": {
"scope": "resource",
"type": "boolean",
Expand Down
26 changes: 21 additions & 5 deletions packages/vscode-plugin/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ const serverOptions: Executable = { command: '', transport: TransportKind.stdio
const clientOptions: LanguageClientOptions = {};

export async function activate(context: ExtensionContext): Promise<void> {
serverOptions.command = Uri.joinPath(
context.extensionUri,
'bin',
`harper-ls${process.platform === 'win32' ? '.exe' : ''}`
).fsPath;
serverOptions.command = getExecutablePath(context);

let manifest: ExtensionManifest;
try {
Expand All @@ -43,6 +39,12 @@ export async function activate(context: ExtensionContext): Promise<void> {
const configs = Object.keys(manifest.contributes.configuration.properties);
context.subscriptions.push(
workspace.onDidChangeConfiguration(async (event) => {
if (event.affectsConfiguration('harper-ls.path')) {
serverOptions.command = getExecutablePath(context);
await startLanguageServer();
return;
}

if (configs.find((c) => event.affectsConfiguration(c))) {
await client?.sendNotification('workspace/didChangeConfiguration', {
settings: { 'harper-ls': workspace.getConfiguration('harper-ls') }
Expand All @@ -58,6 +60,20 @@ export async function activate(context: ExtensionContext): Promise<void> {
await startLanguageServer();
}

function getExecutablePath(context: ExtensionContext): string {
const path = workspace.getConfiguration('harper-ls').get<string>('path', '');

if (path !== '') {
return path;
}

return Uri.joinPath(
context.extensionUri,
'bin',
`harper-ls${process.platform === 'win32' ? '.exe' : ''}`
).fsPath;
}

async function startLanguageServer(): Promise<void> {
if (client && client.needsStop()) {
if (client.diagnostics) {
Expand Down
Loading