Skip to content

Commit

Permalink
Add revealActivateCommandOutput
Browse files Browse the repository at this point in the history
* autoreveal activate command output channel.

* and some bugfixes in config booleans (evergreen problem).
  • Loading branch information
friedbrice committed Mar 14, 2024
1 parent f16c2c6 commit ea09d2e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
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
9 changes: 8 additions & 1 deletion 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
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
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
5 changes: 3 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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 @@ -92,10 +92,11 @@ function restart(output: vscode.OutputChannel, context: vscode.ExtensionContext)
})
}

function makeActivationCommand(parentOutput: IHierarchicalOutputChannel, command: string | undefined): vscode.Disposable {
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))
Expand Down

0 comments on commit ea09d2e

Please sign in to comment.