Skip to content

Commit 048a425

Browse files
Merge pull request #58 from maximbaz/prefer-explainshell
Prefer explainshell when available
2 parents ce72fbb + 6806c96 commit 048a425

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

server/src/server.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,7 @@ export default class BashServer {
107107

108108
const word = this.getWordAtPoint(pos)
109109

110-
if (Builtins.isBuiltin(word)) {
111-
return Builtins.documentation(word).then(doc => ({
112-
contents: {
113-
language: 'plaintext',
114-
value: doc,
115-
},
116-
}))
117-
} else if (this.executables.isExecutableOnPATH(word)) {
118-
return this.executables.documentation(word).then(doc => ({
119-
contents: {
120-
language: 'plaintext',
121-
value: doc,
122-
},
123-
}))
124-
} else if (process.env.EXPLAINSHELL_ENDPOINT !== '') {
110+
if (process.env.EXPLAINSHELL_ENDPOINT !== '') {
125111
const response = await this.analyzer.getExplainshellDocumentation({
126112
pos,
127113
endpoint: process.env.EXPLAINSHELL_ENDPOINT,
@@ -131,19 +117,35 @@ export default class BashServer {
131117
this.connection.console.log(
132118
'getExplainshellDocumentation returned: ' + JSON.stringify(response, null, 4),
133119
)
134-
135-
return null
120+
} else {
121+
return {
122+
contents: {
123+
kind: 'markdown',
124+
value: new TurndownService().turndown(response.helpHTML),
125+
},
126+
}
136127
}
128+
}
137129

138-
return {
130+
if (Builtins.isBuiltin(word)) {
131+
return Builtins.documentation(word).then(doc => ({
139132
contents: {
140-
kind: 'markdown',
141-
value: new TurndownService().turndown(response.helpHTML),
133+
language: 'plaintext',
134+
value: doc,
142135
},
143-
}
144-
} else {
145-
return null
136+
}))
146137
}
138+
139+
if (this.executables.isExecutableOnPATH(word)) {
140+
return this.executables.documentation(word).then(doc => ({
141+
contents: {
142+
language: 'plaintext',
143+
value: doc,
144+
},
145+
}))
146+
}
147+
148+
return null
147149
}
148150

149151
private onDefinition(pos: LSP.TextDocumentPositionParams): LSP.Definition {

0 commit comments

Comments
 (0)