Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9a0194d

Browse files
committed
help provider (for local help)
1 parent 02d1eec commit 9a0194d

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
"onCommand:python.execSelectionInTerminal",
4646
"onCommand:jupyter.runSelectionLine",
4747
"onCommand:jupyter.execCurrentCell",
48-
"onCommand:jupyter.execCurrentCellAndAdvance"
48+
"onCommand:jupyter.execCurrentCellAndAdvance",
49+
"onCommand:python.displayHelp"
4950
],
5051
"main": "./out/client/extension",
5152
"contributes": {
@@ -130,6 +131,11 @@
130131
"command": "jupyter:gotToNextCell",
131132
"title": "Go to next cell",
132133
"category": "Jupyter"
134+
},
135+
{
136+
"command": "python.displayHelp",
137+
"title": "Help",
138+
"category": "Python"
133139
}
134140
],
135141
"menus": {
@@ -789,4 +795,4 @@
789795
"vscode": "^0.11.0",
790796
"webpack": "^1.13.2"
791797
}
792-
}
798+
}

src/client/common/constants.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ export namespace LinterErrors {
7373
}
7474

7575
export namespace Documentation {
76+
export const Home = '/docs/python-path/';
7677
export namespace Jupyter {
77-
export const GettingStarted = "/docs/jupyter_getting-started/";
78-
export const Examples = "/docs/jupyter_examples/";
79-
export const Setup = "/docs/jupyter_prerequisites/";
78+
export const GettingStarted = '/docs/jupyter_getting-started/';
79+
export const Examples = '/docs/jupyter_examples/';
80+
export const Setup = '/docs/jupyter_prerequisites/';
8081
}
8182
}

src/client/helpProvider.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import {Disposable} from 'vscode';
55
import * as path from 'path';
66
import * as http from 'http';
77
import {createDeferred} from './common/helpers';
8+
import {Documentation} from './common/constants';
89
const nodeStatic = require('node-static');
910

1011
let serverAddress = "http://localhost:8080";
11-
let helpPageToDisplay = "/docs/jupyter/";
12+
let helpPageToDisplay = Documentation.Home;
1213
export class TextDocumentContentProvider extends Disposable implements vscode.TextDocumentContentProvider {
1314
private _onDidChange = new vscode.EventEmitter<vscode.Uri>();
1415
private lastUri: vscode.Uri;
@@ -49,11 +50,18 @@ export class HelpProvider {
4950
private disposables: Disposable[] = [];
5051
constructor() {
5152
const textProvider = new TextDocumentContentProvider();
52-
this.disposables.push(vscode.workspace.registerTextDocumentContentProvider(helpSchema, textProvider));
53+
this.disposables.push(vscode.workspace.registerTextDocumentContentProvider(helpSchema, textProvider));
5354
this.disposables.push(vscode.commands.registerCommand('python.displayHelp', (page: string) => {
5455
this.startServer().then(port => {
55-
helpPageToDisplay = page;
56-
vscode.commands.executeCommand('vscode.previewHtml', previewUri, vscode.ViewColumn.Two, 'Help');
56+
let viewColumn = vscode.ViewColumn.Two;
57+
if (!page || typeof page !== 'string' || page.length === 0) {
58+
helpPageToDisplay = Documentation.Home;
59+
viewColumn = vscode.ViewColumn.One;
60+
}
61+
else {
62+
helpPageToDisplay = page;
63+
}
64+
vscode.commands.executeCommand('vscode.previewHtml', previewUri, viewColumn, 'Help');
5765
});
5866
}));
5967
}

0 commit comments

Comments
 (0)