Skip to content

Commit

Permalink
Single preview window previews active editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
technosophos committed Jun 7, 2017
1 parent d7189b1 commit 28bdfcd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Initial support for Draft, and many bug fixes.

Improved support for Kubernetes schema hover tips. Added support for intellisense on `.Values` statements in templates.

The `Helm: Preview Template` view has changed: It now opens only one preview window, and any active editor that is a template is displayed in that window.

## TODO:

- [ ] Add support for a '.vsc-values.yaml' that will merge with 'values.yaml'
7 changes: 6 additions & 1 deletion src/documentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ export class HelmTemplatePreviewDocumentProvider implements vscode.TextDocumentC
public provideTextDocumentContent(uri: vscode.Uri, tok: vscode.CancellationToken): vscode.ProviderResult<string> {
return new Promise<string>((resolve, reject) => {
// The URI is the encapsulated path to the template to render.
let tpl = uri.fsPath
//let tpl = uri.fsPath
if (!vscode.window.activeTextEditor) {
logger.log("FIXME: no editor selected")
return
}
let tpl = vscode.window.activeTextEditor.document.fileName

// First, we need to get the top-most chart:
exec.pickChartForFile(tpl, chartPath => {
Expand Down
4 changes: 3 additions & 1 deletion src/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import * as YAML from 'yamljs';
import * as _ from 'lodash';
import * as fs from "fs";

export const HELM_PREVIEW_SCHEME = 'helm-template-preview'
export const HELM_PREVIEW_URI = HELM_PREVIEW_SCHEME + '://preview'

// This file contains utilities for executing command line tools, notably Helm.

Expand Down Expand Up @@ -48,7 +50,7 @@ export function helmTemplatePreview() {
return
}

let u = vscode.Uri.parse("helm-template-preview://" + filePath)
let u = vscode.Uri.parse(HELM_PREVIEW_URI)
let f = filepath.basename(filePath)
vscode.commands.executeCommand("vscode.previewHtml", u, vscode.ViewColumn.Two, `Preview ${ f }`)
}
Expand Down
22 changes: 9 additions & 13 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const HELM_REQ_MODE: vscode.DocumentFilter = { language: "helm", scheme:
export const HELM_CHART_MODE: vscode.DocumentFilter = { language: "helm", scheme: "file", pattern: "**/Chart.yaml" }
export const HELM_TPL_MODE: vscode.DocumentFilter = { language: "helm", scheme: "file", pattern: "**/templates/*.*" }

export const HELM_PREVIEW_SCHEME = 'helm-template-preview'

export const HELM_INSPECT_SCHEME = 'helm-inspect-values'

// this method is called when your extension is activated
Expand Down Expand Up @@ -66,7 +66,7 @@ export function activate(context: vscode.ExtensionContext) {
vscode.languages.registerHoverProvider(HELM_MODE, new HelmTemplateHoverProvider()),

// Register preview providers
vscode.workspace.registerTextDocumentContentProvider(HELM_PREVIEW_SCHEME, previewProvider),
vscode.workspace.registerTextDocumentContentProvider(exec.HELM_PREVIEW_SCHEME, previewProvider),
vscode.workspace.registerTextDocumentContentProvider(HELM_INSPECT_SCHEME, inspectProvider),

vscode.languages.registerCompletionItemProvider(completionFilter, completionProvider),
Expand All @@ -84,27 +84,23 @@ export function activate(context: vscode.ExtensionContext) {
if (e === vscode.window.activeTextEditor.document) {
let doc = vscode.window.activeTextEditor.document
if (doc.uri.scheme != "file") {
logger.log("Skipping non-file")
return
}
let u = vscode.Uri.parse(HELM_PREVIEW_SCHEME + "://" + doc.uri.fsPath);
let u = vscode.Uri.parse(exec.HELM_PREVIEW_URI)
previewProvider.update(u)
}
});
// On editor change, refresh the YAML preview
vscode.window.onDidChangeActiveTextEditor((e: vscode.TextEditor) => {
if (!editorIsActive()) {
//logger.log("No active editor")
return
}
if (e.document === vscode.window.activeTextEditor.document) {
let doc = vscode.window.activeTextEditor.document
if (doc.uri.scheme != "file") {
return
}
let u = vscode.Uri.parse(HELM_PREVIEW_SCHEME + "://" + doc.uri.fsPath);
previewProvider.update(u)
}
let doc = vscode.window.activeTextEditor.document
if (doc.uri.scheme != "file") {
return
}
let u = vscode.Uri.parse(exec.HELM_PREVIEW_URI)
previewProvider.update(u)
})

disposable.forEach(function(item){
Expand Down

0 comments on commit 28bdfcd

Please sign in to comment.