Skip to content

Commit

Permalink
Remove broken features... (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
friedbrice authored Apr 4, 2024
1 parent 76ec278 commit 675478d
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 141 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ This project adhere's to [Semantic Versioning](https://semver.org/spec/v2.0.0.ht

## [unreleased]

- remove `deactiveCommand` b/c we couldn't guarantee it would always run.
- remove `Alloglot: restart alloglot` b/c it was broken.
- remove dialog box when activation command fails b/c `restart alloglot` was broken.
- (hopefully) better handling of killing child processes.

## [3.2.4]

- fix bug where formatter erases contents of document if it returns no output.
Expand Down
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ Most of the properties are optional, so you can make use of only the features th
```json
{
"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": [
{
"languageId": "cabal",
Expand Down Expand Up @@ -61,7 +59,7 @@ Most of the properties are optional, so you can make use of only the features th
}
},
{
"file": "package-deps-index.tsv",
"file": ".tags-dependencies",
"completionsProvider": true,
"importsProvider": {
"importLinePattern": "import ${module}",
Expand Down Expand Up @@ -176,11 +174,6 @@ export type TConfig = {
*/
revealActivateCommandOutput?: boolean

/**
* A shell command to run on deactivation.
*/
deactivateCommand?: string

/**
* An array of per-language configurations.
*/
Expand Down Expand Up @@ -337,7 +330,7 @@ export type AnnotationsConfig = {
}

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

/**
* Mapping between arbitrary JSON objects and properties of `Annotation`.
* Mapping between arbitrary JSON object 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
9 changes: 0 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
"main": "./dist/extension.js",
"contributes": {
"commands": [
{
"command": "alloglot.command.restart",
"title": "Alloglot: Restart Alloglot"
},
{
"command": "alloglot.command.apisearch",
"title": "Alloglot: Go to API Search"
Expand Down Expand Up @@ -59,11 +55,6 @@
"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.",
"default": null
},
"alloglot.verboseOutput": {
"type": "boolean",
"description": "If `true`, Alloglot will log more output.",
Expand Down
12 changes: 2 additions & 10 deletions src/activationcommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,9 @@ export function makeActivationCommand(parentOutput: IHierarchicalOutputChannel,
const output = parentOutput.split()
reveal && output.show(true)

const proc = AsyncProcess.spawn({ output, command, basedir })

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

proc.catch(err => {
vscode.window
.showErrorMessage<'Ignore' | 'Restart'>(alloglot.ui.activateCommandFailed(err), 'Ignore', 'Restart')
.then(choice => choice === 'Restart' && vscode.commands.executeCommand(alloglot.commands.restart))
})

return vscode.Disposable.from(proc, output)
return vscode.Disposable.from(proc.disposable, output)
}
24 changes: 2 additions & 22 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ export type TConfig = {
*/
revealActivateCommandOutput?: boolean

/**
* A shell command to run on deactivation.
*/
deactivateCommand?: string

/**
* An array of per-language configurations.
*/
Expand Down Expand Up @@ -246,14 +241,13 @@ export namespace Config {
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 || !!revealActivateCommandOutput || !!languages || !!deactivateCommand || !!verboseOutput || !!mergeConfigs || !!grepPath
const settingsExist = !!activateCommand || !!revealActivateCommandOutput || !!languages || !!verboseOutput || !!mergeConfigs || !!grepPath
output.appendLine(alloglot.ui.workspaceConfigExists(settingsExist))
if (settingsExist) return { activateCommand, revealActivateCommandOutput, deactivateCommand, languages, verboseOutput, mergeConfigs, grepPath }
if (settingsExist) return { activateCommand, revealActivateCommandOutput, languages, verboseOutput, mergeConfigs, grepPath }
return undefined
} catch (err) {
output.appendLine(alloglot.ui.couldNotReadWorkspace(err))
Expand All @@ -266,7 +260,6 @@ export namespace Config {
function sanitize(output: vscode.OutputChannel, config: TConfig): TConfig {
try {
config.activateCommand = config.activateCommand?.trim()
config.deactivateCommand = config.deactivateCommand?.trim()
config.grepPath = config.grepPath?.trim()
config.languages = config.languages?.filter(lang => {

Expand Down Expand Up @@ -306,7 +299,6 @@ export namespace Config {
function merge(mask: TConfig, base: TConfig): TConfig {
return {
activateCommand: mask.activateCommand || base.activateCommand,
deactivateCommand: mask.deactivateCommand || base.deactivateCommand,
languages: arrayMerge(mask.languages || [], base.languages || [], lang => lang.languageId, languageMerge),
revealActivateCommandOutput: typeof mask.revealActivateCommandOutput === 'boolean' ? mask.revealActivateCommandOutput : base.revealActivateCommandOutput,
verboseOutput: typeof mask.verboseOutput === 'boolean' ? mask.verboseOutput : base.verboseOutput,
Expand Down Expand Up @@ -359,25 +351,18 @@ export namespace alloglot {

export namespace ui {
export const activateCommandDone = (cmd: string) => `Activation command “${cmd}” has completed.`
export const activateCommandFailed = (err: any) => `Activation command has failed: ${err}\n\nIgnore the failure or restart Alloglot?`
export const addImport = (moduleName: string) => `Add import: ${moduleName}`
export const annotationsStarted = 'Annotations started.'
export const appliedEdit = (success: boolean) => `Applied edit: ${success}`
export const applyingTransformation = (t: any, xs: Array<string>) => `Applying single transformation ${JSON.stringify(t)} to split string array ${xs}`
export const applyingTransformations = (t: any, x: string) => `Applying transformations ${JSON.stringify(t)} to string ${x}`
export const commandKilled = (cmd: string) => `Killed “${cmd}”.`
export const commandLogs = (cmd: string, logs: string) => `Logs from “${cmd}”:\n\t${logs}`
export const commandNoOutput = (cmd: string) => `Received no output from “${cmd}”.`
export const couldNotReadFallback = (err: any) => `Could not read fallback configuration: ${err}`
export const couldNotReadWorkspace = (err: any) => `Could not read workspace configuration: ${err}`
export const couldNotSanitizeConfig = (err: any) => `Configuration is malformed: ${err}`
export const creatingApiSearch = (langIds: Array<string>) => `Creating API search command for languages: ${langIds}`
export const creatingTagsSource = (path: string) => `Creating tags source for path: ${path}`
export const deactivatedAlloglot = 'Deactivated Alloglot.'
export const deactivatingAlloglot = 'Deactivating Alloglot...'
export const deactivateCommandDone = (cmd: string) => `Deactivation command has completed: ${cmd}`
export const deactivateCommandFailed = (err: any) => `Deactivation command has completed: ${err}`
export const disposingAlloglot = 'Disposing Alloglot...'
export const errorKillingCommand = (cmd: string, err: any) => `Error killing “${cmd}”:\n\t${err}`
export const errorRunningCommand = (cmd: string, err: any) => `Error running “${cmd}”:\n\t${err}`
export const fileMatcherResult = (result: any) => `Match: ${result}`
Expand All @@ -399,7 +384,6 @@ export namespace alloglot {
export const ranCommand = (cmd: string) => `Ran “${cmd}”.`
export const readingFallbackConfig = (path: string) => `Reading fallback configuration from path: ${path}`
export const readingWorkspaceSettings = 'Reading configuration from workspace settings'
export const readyToRestart = 'Ready to restart Alloglot.'
export const registeredCompletionsProvider = 'Registered completions provider.'
export const registeredDefinitionsProvider = 'Registered definitions provider.'
export const registeredImportsProvider = 'Registered imports provider.'
Expand All @@ -411,7 +395,6 @@ export namespace alloglot {
export const renderedImportLine = (line?: string) => `Rendered import line: ${line}`
export const renderedModuleName = (name?: string) => `Rendered module name: ${name}`
export const renderingImportLine = (tag: any) => `Rendering import line for tag: ${JSON.stringify(tag)}`
export const restartingAlloglot = 'Restarting Alloglot...'
export const runningCommand = (cmd: string, cwd?: string) => `Running “${cmd}” in “${cwd}”...`
export const runningSuggestImports = 'Running suggest imports...'
export const splittingOutputChannel = (name: string) => `Creating new output channel: ${name}`
Expand All @@ -423,7 +406,6 @@ export namespace alloglot {
export const stoppingLanguageClient = 'Stopping language client...'
export const tagsStarted = 'Tags started.'
export const transformationResult = (x: string) => `Result: ${x}`
export const usingActivateCommandOutput = (channelId: string) => `Activation command stdout broadcasting to channel: ${channelId}`
export const usingConfig = (config: any) => `Using configuration:\n${JSON.stringify(config, null, 2)}`
export const usingFileMatcher = (matcher: any) => `File matcher: ${matcher}`
export const workspaceConfigExists = (exists: boolean) => `Configuration exists in settings: ${exists}`
Expand All @@ -448,7 +430,6 @@ export namespace alloglot {

export namespace commands {
const root = `${alloglot.root}.command` as const
export const restart = `${root}.restart` as const
export const apiSearch = `${root}.apisearch` as const
export const suggestImports = `${root}.suggestimports` as const
}
Expand All @@ -461,7 +442,6 @@ export namespace alloglot {
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
export const mergeConfigs = 'mergeConfigs' as const
}
Expand Down
61 changes: 3 additions & 58 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,17 @@ import { makeActivationCommand } from './activationcommand'
import { makeAnnotations } from './annotations'
import { makeApiSearch } from './apisearch'
import { makeClient } from './client'
import { Config, TConfig, alloglot } from './config'
import { Config, alloglot } from './config'
import { makeFormatter } from './formatter'
import { makeOnSaveRunner } from './onsaverunner'
import { makeTags } from './tags'
import { AsyncProcess, HierarchicalOutputChannel, IHierarchicalOutputChannel } from './utils'

let globalOutput: IHierarchicalOutputChannel | undefined
let globalContext: vscode.ExtensionContext | undefined
let globalConfig: TConfig | undefined
import { HierarchicalOutputChannel } from './utils'

export function activate(context: vscode.ExtensionContext): void {
globalContext = context
const output = globalOutput || HierarchicalOutputChannel.make(alloglot.root)
globalOutput = output
const output = HierarchicalOutputChannel.make(alloglot.root)

output.appendLine(alloglot.ui.startingAlloglot)
const config = Config.make(output)
globalConfig = config
output.appendLine(alloglot.ui.usingConfig(config))

const langs = config.languages || []
Expand All @@ -30,12 +23,6 @@ export function activate(context: vscode.ExtensionContext): void {
const grepPath = config.grepPath || 'grep'

context.subscriptions.push(
// Restart the extension when the user runs the restart command.
vscode.commands.registerCommand(alloglot.commands.restart, () => restart(output, context)),

// Restart the extension when the configuration changes.
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, config.revealActivateCommandOutput),

Expand All @@ -50,45 +37,3 @@ export function activate(context: vscode.ExtensionContext): void {
...langs.map(lang => makeTags(output.local(alloglot.components.tags).local(lang.languageId), grepPath, lang, verboseOutput))
)
}

export function deactivate(): Promise<void> {
const command = globalConfig?.deactivateCommand
globalConfig = undefined
const basedir = vscode.workspace.workspaceFolders?.[0].uri

function cleanup(): Promise<void> {
return new Promise((resolve, reject) => {
try {
globalOutput?.appendLine(alloglot.ui.deactivatingAlloglot)
globalContext && globalContext.subscriptions.forEach(sub => sub.dispose())
globalContext = undefined
globalOutput?.appendLine(alloglot.ui.deactivatedAlloglot)
resolve()
} catch (err) {
reject(err)
}
})
}

if (command) {
return AsyncProcess.exec({ output: globalOutput, command, basedir }, () => undefined)
.then(() => {
globalOutput?.appendLine(alloglot.ui.deactivateCommandDone(command))
return cleanup()
})
.catch(err => {
globalOutput?.appendLine(alloglot.ui.deactivateCommandFailed(err))
return cleanup()
})
} else {
return cleanup()
}
}

function restart(output: vscode.OutputChannel, context: vscode.ExtensionContext): void {
output.appendLine(alloglot.ui.restartingAlloglot)
deactivate().then(() => {
output.appendLine(alloglot.ui.readyToRestart)
activate(context)
})
}
4 changes: 2 additions & 2 deletions src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export function makeFormatter(output: vscode.OutputChannel, config: LanguageConf
stdout => stdout ? [new vscode.TextEdit(entireDocument, stdout)] : []
)

disposal.insert(proc)
return proc
disposal.insert(proc.disposable)
return proc.promise
}
}
)
Expand Down
2 changes: 1 addition & 1 deletion src/onsaverunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function makeOnSaveRunner(output: vscode.OutputChannel, config: LanguageC
const refreshTags = (doc: vscode.TextDocument) => {
if (doc.languageId === languageId) {
const command = onSaveCommand.replace('${file}', doc.fileName)
disposal.insert(AsyncProcess.exec({ output, command, basedir }, () => undefined))
disposal.insert(AsyncProcess.exec({ output, command, basedir }, () => undefined).disposable)
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ namespace TagsSource {

if (initTagsCommand) {
const command = initTagsCommand
disposal.insert(AsyncProcess.exec({ output, command, basedir }, () => undefined))
disposal.insert(AsyncProcess.exec({ output, command, basedir }, () => undefined).disposable)
}

const onSaveWatcher = (() => {
Expand All @@ -238,7 +238,7 @@ namespace TagsSource {
const refreshTags = (doc: vscode.TextDocument) => {
if (doc.languageId === languageId) {
const command = refreshTagsCommand.replace('${file}', doc.fileName)
disposal.insert(AsyncProcess.exec({ output, command, basedir }, () => undefined))
disposal.insert(AsyncProcess.exec({ output, command, basedir }, () => undefined).disposable)
}
}

Expand All @@ -250,16 +250,16 @@ namespace TagsSource {
if (!prefix) return Promise.resolve([])
const escaped = prefix.replace(/(["\s'$`\\])/g, '\\$1')
const proc = grep(config, new RegExp(`^${escaped}`), limit, output)
disposal.insert(proc)
return proc
disposal.insert(proc.disposable)
return proc.promise
},

findExact(exact, limit = 100) {
if (!exact) return Promise.resolve([])
const escaped = exact.replace(/(["\s'$`\\])/g, '\\$1')
const proc = grep(config, new RegExp(`^${escaped}\\t`), limit, output)
disposal.insert(proc)
return proc
disposal.insert(proc.disposable)
return proc.promise
},

dispose() {
Expand Down
Loading

0 comments on commit 675478d

Please sign in to comment.