From 6806c9654fbd07145641354e72a9ba0274c7f304 Mon Sep 17 00:00:00 2001 From: Maxim Baz Date: Wed, 11 Jul 2018 14:08:43 +0200 Subject: [PATCH] Prefer explainshell when available --- server/src/server.ts | 48 +++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/server/src/server.ts b/server/src/server.ts index 7bbee9626..1b134a530 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -107,21 +107,7 @@ export default class BashServer { const word = this.getWordAtPoint(pos) - if (Builtins.isBuiltin(word)) { - return Builtins.documentation(word).then(doc => ({ - contents: { - language: 'plaintext', - value: doc, - }, - })) - } else if (this.executables.isExecutableOnPATH(word)) { - return this.executables.documentation(word).then(doc => ({ - contents: { - language: 'plaintext', - value: doc, - }, - })) - } else if (process.env.EXPLAINSHELL_ENDPOINT !== '') { + if (process.env.EXPLAINSHELL_ENDPOINT !== '') { const response = await this.analyzer.getExplainshellDocumentation({ pos, endpoint: process.env.EXPLAINSHELL_ENDPOINT, @@ -131,19 +117,35 @@ export default class BashServer { this.connection.console.log( 'getExplainshellDocumentation returned: ' + JSON.stringify(response, null, 4), ) - - return null + } else { + return { + contents: { + kind: 'markdown', + value: new TurndownService().turndown(response.helpHTML), + }, + } } + } - return { + if (Builtins.isBuiltin(word)) { + return Builtins.documentation(word).then(doc => ({ contents: { - kind: 'markdown', - value: new TurndownService().turndown(response.helpHTML), + language: 'plaintext', + value: doc, }, - } - } else { - return null + })) } + + if (this.executables.isExecutableOnPATH(word)) { + return this.executables.documentation(word).then(doc => ({ + contents: { + language: 'plaintext', + value: doc, + }, + })) + } + + return null } private onDefinition(pos: LSP.TextDocumentPositionParams): LSP.Definition {