Skip to content

Commit c8f7039

Browse files
committed
Add openSourceInHackage setting.
1 parent e7b933d commit c8f7039

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@
9999
"default": true,
100100
"description": "When opening 'Documentation' for external libraries, open in hackage by default. Set to false to instead open in vscode."
101101
},
102+
"haskell.openSourceInHackage": {
103+
"scope": "resource",
104+
"type": "boolean",
105+
"default": true,
106+
"description": "When opening 'Source' for external libraries, open in hackage by default. Set to false to instead open in vscode."
107+
},
102108
"haskell.trace.server": {
103109
"scope": "resource",
104110
"type": "string",

src/docsBrowser.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,8 @@ export namespace DocsBrowser {
7272
}
7373

7474
// registers the browser in VSCode infrastructure
75-
export function registerDocsBrowser(alwaysOpenInHackage: boolean): Disposable {
76-
if (alwaysOpenInHackage) {
77-
return commands.registerCommand('haskell.showDocumentation', openDocumentationOnHackage);
78-
} else {
79-
return commands.registerCommand('haskell.showDocumentation', showDocumentation);
80-
}
75+
export function registerDocsBrowser(): Disposable {
76+
return commands.registerCommand('haskell.showDocumentation', showDocumentation);
8177
}
8278

8379
async function openDocumentationOnHackage({
@@ -143,6 +139,8 @@ export namespace DocsBrowser {
143139
}
144140

145141
function processLink(ms: MarkdownString | MarkedString): string | MarkdownString {
142+
const openDocsInHackage = workspace.getConfiguration('haskell').get('openDocumentationInHackage');
143+
const openSourceInHackage = workspace.getConfiguration('haskell').get('openSourceInHackage');
146144
function transform(s: string): string {
147145
return s.replace(
148146
/\[(.+)\]\((file:.+\/doc\/(?:.*html\/libraries\/)?([^\/]+)\/(?:.*\/)?(.+\.html#?.*))\)/gi,
@@ -151,15 +149,25 @@ export namespace DocsBrowser {
151149
if (title == 'Documentation') {
152150
hackageUri = `https://hackage.haskell.org/package/${packageName}/docs/${fileAndAnchor}`;
153151
const encoded = encodeURIComponent(JSON.stringify({ title, localPath, hackageUri }));
154-
const cmd = 'command:haskell.showDocumentation?' + encoded;
152+
let cmd: string;
153+
if (openDocsInHackage) {
154+
cmd = 'command:haskell.openDocumentationOnHackage?' + encoded;
155+
} else {
156+
cmd = 'commnad:haskell.showDocumentation?' + encoded;
157+
}
155158
return `[${title}](${cmd})`;
156159
} else if (title == 'Source') {
157160
hackageUri = `https://hackage.haskell.org/package/${packageName}/docs/src/${fileAndAnchor.replace(
158161
/-/gi,
159162
'.'
160163
)}`;
161164
const encoded = encodeURIComponent(JSON.stringify({ title, localPath, hackageUri }));
162-
const cmd = 'command:haskell.showDocumentation?' + encoded;
165+
let cmd: string;
166+
if (openSourceInHackage) {
167+
cmd = 'command:haskell.openDocumentationOnHackage?' + encoded;
168+
} else {
169+
cmd = 'command:haskell.showDocumentation?' + encoded;
170+
}
163171
return `[${title}](${cmd})`;
164172
} else {
165173
return s;

src/extension.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ export async function activate(context: ExtensionContext) {
9090
context.subscriptions.push(ImportIdentifier.registerCommand());
9191

9292
// Set up the documentation browser.
93-
const openInHackage = workspace.getConfiguration('haskell').openDocumentationInHackage;
94-
const docsDisposable = DocsBrowser.registerDocsBrowser(openInHackage);
93+
const docsDisposable = DocsBrowser.registerDocsBrowser();
9594
context.subscriptions.push(docsDisposable);
9695

9796
const openOnHackageDisposable = DocsBrowser.registerDocsOpenOnHackage();

0 commit comments

Comments
 (0)