Skip to content

Commit

Permalink
Merge pull request #330 from mcecode/vscode-executable-path
Browse files Browse the repository at this point in the history
Support using a different `harper-ls` executable than the one bundled in the VSCode extension
  • Loading branch information
elijah-potter authored Dec 26, 2024
2 parents 0ef0f96 + d70908a commit 1cd29ac
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
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

0 comments on commit 1cd29ac

Please sign in to comment.