Skip to content

Commit 42aff8b

Browse files
committed
Added basic code.
1 parent fd5fc9e commit 42aff8b

File tree

8 files changed

+1781
-5406
lines changed

8 files changed

+1781
-5406
lines changed

.vscode/launch.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
"runtimeExecutable": "${execPath}",
3535
"args": [
3636
"--extensionDevelopmentPath=${workspaceRoot}/code",
37-
"--folder-uri=${workspaceRoot}/docs",
38-
"--folder-uri=${workspaceRoot}/lib/esbonio/tests/sphinx-default/workspace"
37+
"--folder-uri=/Users/lextm/docs/test-field"
3938
],
4039
"outFiles": [
4140
"${workspaceRoot}/code/dist/node/**/*.js"

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"[python]": {
33
"editor.defaultFormatter": "ms-python.black-formatter",
44
"editor.codeActionsOnSave": {
5-
"source.organizeImports": true
5+
"source.organizeImports": "explicit"
66
},
77
"editor.formatOnSave": true,
88
},

code/package-lock.json

-5,402
This file was deleted.

code/package.json

+11
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@
7575
"icon": "$(open-preview)",
7676
"category": "Esbonio"
7777
},
78+
{
79+
"command": "esbonio.preview.showSource",
80+
"title": "Show Source",
81+
"icon": "$(go-to-file)",
82+
"category": "Esbonio"
83+
},
7884
{
7985
"command": "esbonio.server.restart",
8086
"title": "Restart Language Server",
@@ -316,6 +322,11 @@
316322
"alt": "esbonio.preview.open",
317323
"group": "navigation",
318324
"when": "resourceLangId == restructuredtext"
325+
},
326+
{
327+
"command": "esbonio.preview.showSource",
328+
"group": "navigation",
329+
"when": "restructuredtextPreviewFocus"
319330
}
320331
]
321332
},

code/src/common/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export namespace Server {
55
export namespace Commands {
66
export const OPEN_PREVIEW = "esbonio.preview.open"
77
export const OPEN_PREVIEW_TO_SIDE = "esbonio.preview.openSide"
8+
export const SHOW_SOURCE = "esbonio.preview.showSource"
89
export const PREVIEW_FILE = "esbonio.server.previewFile"
910

1011
export const RESTART_SERVER = "esbonio.server.restart"

code/src/node/client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export class EsbonioClient {
165165
}
166166

167167
// Isolate the Python interpreter from the user's environment - we brought our own.
168-
command.push(...pythonCommand, "-S")
168+
command.push(...pythonCommand)
169169

170170
if ((serverDevtools || sphinxDevtools) && lsp_devtools) {
171171
// Requires lsp-devtools to be on the user's PATH.

code/src/node/preview.ts

+28
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ interface PreviewFileResult {
1414

1515
export class PreviewManager {
1616

17+
private static readonly rstPreviewActiveContextKey =
18+
'restructuredtextPreviewFocus';
1719
private panel?: vscode.WebviewPanel
1820

1921
// The uri of the document currently shown in the preview pane
@@ -30,6 +32,9 @@ export class PreviewManager {
3032
context.subscriptions.push(
3133
vscode.commands.registerTextEditorCommand(Commands.OPEN_PREVIEW_TO_SIDE, this.openPreviewToSide, this)
3234
)
35+
context.subscriptions.push(
36+
vscode.commands.registerTextEditorCommand(Commands.SHOW_SOURCE, this.showSource, this)
37+
)
3338
context.subscriptions.push(
3439
vscode.window.onDidChangeActiveTextEditor(this.onDidChangeEditor, this)
3540
)
@@ -74,6 +79,19 @@ export class PreviewManager {
7479
return await this.previewEditor(editor, vscode.ViewColumn.Beside)
7580
}
7681

82+
async showSource() {
83+
if (!this.currentUri) {
84+
return
85+
}
86+
87+
let editor = findEditorFor(this.currentUri)
88+
if (!editor) {
89+
return
90+
}
91+
92+
await vscode.window.showTextDocument(editor.document, { preview: false })
93+
}
94+
7795
private scrollEditor(params: { line: number }) {
7896
let editor = findEditorFor(this.currentUri)
7997
if (!editor) {
@@ -133,6 +151,7 @@ export class PreviewManager {
133151

134152
this.currentUri = editor.document.uri
135153
panel.webview.postMessage({ 'show': result.uri })
154+
this.setPreviewActiveContext(true)
136155
}
137156

138157
private getPanel(placement: vscode.ViewColumn): vscode.WebviewPanel {
@@ -267,10 +286,19 @@ export class PreviewManager {
267286
this.panel.onDidDispose(() => {
268287
this.panel = undefined
269288
this.currentUri = undefined
289+
this.setPreviewActiveContext(false)
270290
})
271291

272292
return this.panel
273293
}
294+
295+
private setPreviewActiveContext(value: boolean) {
296+
vscode.commands.executeCommand(
297+
'setContext',
298+
PreviewManager.rstPreviewActiveContextKey,
299+
value
300+
)
301+
}
274302
}
275303

276304

0 commit comments

Comments
 (0)