Skip to content
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

Add revealActivateCommandOutput #60

Merged
merged 2 commits into from
Mar 14, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ This project adhere's to [Semantic Versioning](https://semver.org/spec/v2.0.0.ht

## [unreleased]

- autoreveal activate command output channel.
- and some bugfixes in config booleans (evergreen problem).

## [3.1.0]

- Add `onSaveCommand` to `LanguageConfig`. Can now configure a command to run on saved files.
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Most of the properties are optional, so you can make use of only the features th

```json
{
"alloglot.activateCommand": "ghcid",
"alloglot.activateCommand": "ghcid --command=\"cabal repl --ghc-options=-ddump-json\" --output=\"ghc-out.json\"",
"alloglot.revealActivateCommandOutput": true,
"alloglot.deactivateCommand": "pgrep ghc | xargs kill",
"alloglot.languages": [
{
Expand All @@ -33,6 +34,7 @@ Most of the properties are optional, so you can make use of only the features th
"languageId": "haskell",
"serverCommand": "static-ls",
"formatCommand": "fourmolu --mode stdout --stdin-input-file ${file}",
"onSaveCommand": ".bin/hlint --json --no-exit-code ${file} > hlint-out.json",
"apiSearchUrl": "https://hoogle.haskell.org/?hoogle=${query}",
"tags": [
{
Expand Down Expand Up @@ -169,6 +171,11 @@ export type TConfig = {
*/
activateCommand?: string

/**
* If `true`, Alloglot will automatically reveal the activation command's output channel.
*/
revealActivateCommandOutput?: boolean

/**
* A shell command to run on deactivation.
*/
Expand Down Expand Up @@ -330,7 +337,7 @@ export type AnnotationsConfig = {
}

/**
* Intermediate representation of compiler-generated JSON output and VS Code diagnostics.
* Intermediate representation between compiler JSON output and VS Code diagnostics.
*/
export type Annotation = {
source: string
Expand All @@ -346,7 +353,7 @@ export type Annotation = {
}

/**
* Mapping between arbitrary JSON object and properties of `Annotation`.
* Mapping between arbitrary JSON objects and properties of `Annotation`.
* Each property is an array of strings that will be used as a path into the JSON object.
*/
export type AnnotationsMapping = {
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
"description": "A shell command to run on activation. The command will run asynchronously. It will be killed (if it's still running) on deactivation.",
"default": null
},
"alloglot.revealActivateCommandOutput": {
"type": "boolean",
"description": "If `true`, Alloglot will automatically reveal the activation command's output channel.",
"default": null
},
"alloglot.deactivateCommand": {
"type": "string",
"description": "A shell command to run on deactivation.",
Expand Down
17 changes: 17 additions & 0 deletions src/activationcommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as vscode from 'vscode'

import { alloglot } from './config'
import { AsyncProcess, IHierarchicalOutputChannel } from './utils'

export function makeActivationCommand(parentOutput: IHierarchicalOutputChannel, command: string | undefined, reveal: boolean | undefined): vscode.Disposable {
if (!command) return vscode.Disposable.from()
const basedir = vscode.workspace.workspaceFolders?.[0].uri
const output = parentOutput.split()
reveal && output.show(true)

const proc = AsyncProcess.make({ output, command, basedir }, () => {
parentOutput.appendLine(alloglot.ui.activateCommandDone(command))
})

return vscode.Disposable.from(proc, output)
}
16 changes: 12 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export type TConfig = {
*/
activateCommand?: string

/**
* If `true`, Alloglot will automatically reveal the activation command's output channel.
*/
revealActivateCommandOutput?: boolean

/**
* A shell command to run on deactivation.
*/
Expand Down Expand Up @@ -240,14 +245,15 @@ export namespace Config {
output.appendLine(alloglot.ui.readingWorkspaceSettings)
const workspaceSettings = vscode.workspace.getConfiguration(alloglot.config.root)
const activateCommand = workspaceSettings.get<string>(alloglot.config.activateCommand)
const revealActivateCommandOutput = workspaceSettings.get<boolean>(alloglot.config.revealActivateCommandOutput)
const deactivateCommand = workspaceSettings.get<string>(alloglot.config.deactivateCommand)
const languages = workspaceSettings.get<Array<LanguageConfig>>(alloglot.config.languages)
const verboseOutput = workspaceSettings.get<boolean>(alloglot.config.verboseOutput)
const mergeConfigs = workspaceSettings.get<boolean>(alloglot.config.mergeConfigs)
const grepPath = workspaceSettings.get<string>(alloglot.config.grepPath)
const settingsExist = !!activateCommand || !!languages || !!deactivateCommand || !!verboseOutput || !!mergeConfigs || !!grepPath
const settingsExist = !!activateCommand || !!revealActivateCommandOutput || !!languages || !!deactivateCommand || !!verboseOutput || !!mergeConfigs || !!grepPath
output.appendLine(alloglot.ui.workspaceConfigExists(settingsExist))
if (settingsExist) return { activateCommand, deactivateCommand, languages, verboseOutput, mergeConfigs, grepPath }
if (settingsExist) return { activateCommand, revealActivateCommandOutput, deactivateCommand, languages, verboseOutput, mergeConfigs, grepPath }
return undefined
} catch (err) {
output.appendLine(alloglot.ui.couldNotReadWorkspace(err))
Expand Down Expand Up @@ -302,8 +308,9 @@ export namespace Config {
activateCommand: mask.activateCommand || base.activateCommand,
deactivateCommand: mask.deactivateCommand || base.deactivateCommand,
languages: arrayMerge(mask.languages || [], base.languages || [], lang => lang.languageId, languageMerge),
verboseOutput: mask.verboseOutput || base.verboseOutput,
mergeConfigs: mask.mergeConfigs || base.mergeConfigs
revealActivateCommandOutput: typeof mask.revealActivateCommandOutput === 'boolean' ? mask.revealActivateCommandOutput : base.revealActivateCommandOutput,
verboseOutput: typeof mask.verboseOutput === 'boolean' ? mask.verboseOutput : base.verboseOutput,
mergeConfigs: typeof mask.mergeConfigs === 'boolean' ? mask.mergeConfigs : base.mergeConfigs
}
}

Expand Down Expand Up @@ -451,6 +458,7 @@ export namespace alloglot {
export const grepPath = 'grepPath' as const
export const languages = 'languages' as const
export const activateCommand = 'activateCommand' as const
export const revealActivateCommandOutput = 'revealActivateCommandOutput' as const
export const onSaveCommand = 'onSaveCommand' as const
export const deactivateCommand = 'deactivateCommand' as const
export const verboseOutput = 'verboseOutput' as const
Expand Down
15 changes: 2 additions & 13 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode'

import { makeActivationCommand } from './activationcommand'
import { makeAnnotations } from './annotations'
import { makeApiSearch } from './apisearch'
import { makeClient } from './client'
Expand Down Expand Up @@ -36,7 +37,7 @@ export function activate(context: vscode.ExtensionContext): void {
vscode.workspace.onDidChangeConfiguration(ev => ev.affectsConfiguration(alloglot.config.root) && restart(output, context)),

// Start the activation component if it's configured.
makeActivationCommand(output.local(alloglot.components.activateCommand), config.activateCommand),
makeActivationCommand(output.local(alloglot.components.activateCommand), config.activateCommand, config.revealActivateCommandOutput),

// Start the API search component because VSCode can't dynamically create commands.
makeApiSearch(output.local(alloglot.components.apiSearch), config),
Expand Down Expand Up @@ -91,15 +92,3 @@ function restart(output: vscode.OutputChannel, context: vscode.ExtensionContext)
activate(context)
})
}

function makeActivationCommand(parentOutput: IHierarchicalOutputChannel, command: string | undefined): vscode.Disposable {
if (!command) return vscode.Disposable.from()
const basedir = vscode.workspace.workspaceFolders?.[0].uri
const output = parentOutput.split()

const proc = AsyncProcess.make({ output, command, basedir }, () => {
parentOutput.appendLine(alloglot.ui.activateCommandDone(command))
})

return vscode.Disposable.from(proc, output)
}
Loading