Skip to content

Commit

Permalink
feat: provide an easy way for users to specify the ods style of the r…
Browse files Browse the repository at this point in the history
…esults and automatically use a style that reasonably matches the vs code theme by default (#473)

Added a new extension setting to allow users to set the ODS style to use with HTML results. The option defaults to "(auto)", which automatically selects a style that most closely matches the VS Code application theme. "(default)" uses the default ODS style configured on the server by not explicitly specifying a style (style= statement) in the generated code.

("(auto)" selects a light ODS style (Illuminate) for light vscode color themes, a dark ODS style (Ignite) for dark vscode color themes, a dark high contrast  ODS style (High Contrast) for vscode high contrast dark color theme, and Illuminate for vscode high contrast light color theme. HighContrastLight does not currently have a good (light high contrast) ODS style to map to, so for now using Illuminate, since it is light and has pretty strong contrast (better than the default high contrast, which is dark). These are not perfect matches for all vscode color themes, but at least light with light and dark with dark.)
  • Loading branch information
clangsmith authored Sep 6, 2023
1 parent 00d7a9f commit 96116bd
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Added

- Option to specify ODS style (match VS Code color theme by default) ([#473](https://github.com/sassoftware/vscode-sas-extension/pull/473))
- Locale script to ease translating extension into different languages. See `CONTRIBUTING.md` for more information. ([#464](https://github.com/sassoftware/vscode-sas-extension/pull/464))

## [v1.2.0] - 2023-08-11
Expand Down
12 changes: 7 additions & 5 deletions client/src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type { BaseLanguageClient } from "vscode-languageclient";
import { LogFn as LogChannelFn } from "../components/LogChannel";
import { getSession } from "../connection";
import { profileConfig, switchProfile } from "./profile";
import { wrapCode } from "../components/utils";

interface FoldingBlock {
startLine: number;
Expand All @@ -26,7 +27,7 @@ interface FoldingBlock {

let running = false;

function getCode(outputHtml: boolean, selected = false, uri?: Uri): string {
function getCode(selected = false, uri?: Uri): string {
const editor = uri
? window.visibleTextEditors.find(
(editor) => editor.document.uri.toString() === uri.toString(),
Expand All @@ -51,9 +52,9 @@ function getCode(outputHtml: boolean, selected = false, uri?: Uri): string {
code = doc?.getText();
}

return outputHtml
? "ods html5;\n" + code + "\n;run;quit;ods html5 close;"
: code;
code = wrapCode(code);

return code;
}

async function getSelectedRegions(
Expand Down Expand Up @@ -116,7 +117,8 @@ async function runCode(selected?: boolean, uri?: Uri) {
const outputHtml = !!workspace
.getConfiguration("SAS")
.get("session.outputHtml");
const code = getCode(outputHtml, selected, uri);

const code = getCode(selected, uri);

const session = getSession();
session.onLogFn = LogChannelFn;
Expand Down
11 changes: 2 additions & 9 deletions client/src/components/notebook/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import * as vscode from "vscode";
import { getSession } from "../../connection";
import { Deferred, deferred } from "../utils";
import { wrapCode } from "../utils";

export class NotebookController {
readonly controllerId = "sas-notebook-controller-id";
Expand Down Expand Up @@ -123,23 +124,15 @@ export class NotebookController {
}

const getCode = (doc: vscode.TextDocument) => {
const outputHtml = !!vscode.workspace
.getConfiguration("SAS")
.get("session.outputHtml");

let code = doc.getText();
if (doc.languageId === "sql") {
code = wrapSQL(code);
} else if (doc.languageId === "python") {
code = wrapPython(code);
}
return outputHtml ? wrapHTML5(code) : code;
return wrapCode(code);
};

const wrapHTML5 = (code: string) => `ods html5;
${code}
;run;quit;ods html5 close;`;

const wrapSQL = (code: string) => `proc sql;
${code}
;quit;`;
Expand Down
50 changes: 50 additions & 0 deletions client/src/components/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,56 @@
// Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { window, workspace, ColorThemeKind } from "vscode";

export function wrapCode(code: string): string {
const outputHtml = !!workspace
.getConfiguration("SAS")
.get("session.outputHtml");
const htmlStyle: string = workspace
.getConfiguration("SAS")
.get("results.html.style");

if (outputHtml) {
let odsStyle;
switch (htmlStyle) {
case "(auto)":
switch (window.activeColorTheme.kind) {
case ColorThemeKind.Light:
odsStyle = "Illuminate";
break;
case ColorThemeKind.Dark:
odsStyle = "Ignite";
break;
case ColorThemeKind.HighContrast:
odsStyle = "HighContrast";
break;
case ColorThemeKind.HighContrastLight:
odsStyle = "Illuminate";
break;
default:
odsStyle = "";
break;
}
break;
case "(server default)":
odsStyle = "";
break;
default:
odsStyle = htmlStyle;
break;
}

const usercode = code;
code = `ods html5`;
if (odsStyle) {
code += ` style=${odsStyle}`;
}
code += ";\n" + usercode + "\n;run;quit;ods html5 close;";
}
return code;
}

export interface Deferred<T> {
promise: Promise<T>;
resolve: (value: T | PromiseLike<T>) => void;
Expand Down
34 changes: 33 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,38 @@
"default": true,
"description": "%configuration.SAS.session.outputHtml%"
},
"SAS.results.html.style": {
"order": 1,
"type": "string",
"default": "(auto)",
"enum": [
"(auto)",
"(server default)",
"Aqua",
"Daisy",
"Dove",
"HighContrast",
"HighContrastLarge",
"HTMLBlue",
"HTMLEncore",
"Ignite",
"Illuminate",
"Journal",
"Journal2",
"Journal3",
"Marine",
"Midnight",
"Moonflower",
"Opal",
"Pearl",
"Sapphire"
],
"enumDescriptions": [
"%configuration.SAS.results.html.style.(auto)%",
"%configuration.SAS.results.html.style.(server default)%"
],
"description": "%configuration.SAS.results.html.style%"
},
"SAS.userProvidedCertificates": {
"type": "array",
"description": "%configuration.SAS.userProvidedCertificates%",
Expand All @@ -128,7 +160,7 @@
}
},
"SAS.connectionProfiles": {
"order": 1,
"order": 2,
"type": "object",
"description": "%configuration.SAS.connectionProfiles%",
"properties": {
Expand Down
3 changes: 3 additions & 0 deletions package.nls.de.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
"configuration.SAS.connectionProfiles.profiles.tokenFile": "SAS Viya Token Datei",
"configuration.SAS.connectionProfiles.profiles.username": "SAS Viya Benutzer ID",
"configuration.SAS.session.outputHtml": "Aktiveren/deaktiveren der ODS HTML5 Ausgabe",
"configuration.SAS.results.html.style": "Lege den Style für ODS HTML5 Ergebnisse fest.",
"configuration.SAS.results.html.style.(auto)": "Lassen Sie die Erweiterung einen Stil auswählen, der dem Farbschema am ehesten entspricht.",
"configuration.SAS.results.html.style.(server default)": "Nutze den auf dem SAS Server konfigurierten Standardstyle.",
"configuration.SAS.userProvidedCertificates": "Bereitstellung von vertrauenswürdigen CA-Zertifikatsdateien",
"notebooks.SAS.htmlRenderer": "SAS HTML Renderer",
"notebooks.SAS.logRenderer": "SAS Log Renderer",
Expand Down
3 changes: 3 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
"configuration.SAS.connectionProfiles.profiles.tokenFile": "SAS Viya Token File",
"configuration.SAS.connectionProfiles.profiles.username": "SAS Viya User ID",
"configuration.SAS.session.outputHtml": "Enable/disable ODS HTML5 output",
"configuration.SAS.results.html.style": "Specifies the style for ODS HTML5 results.",
"configuration.SAS.results.html.style.(auto)": "Let the extension pick a style that most closely matches the color theme.",
"configuration.SAS.results.html.style.(server default)": "Default to the style configured on the SAS server.",
"configuration.SAS.userProvidedCertificates": "Provide trusted CA certificate files",
"notebooks.SAS.htmlRenderer": "SAS HTML Renderer",
"notebooks.SAS.logRenderer": "SAS Log Renderer",
Expand Down
3 changes: 3 additions & 0 deletions package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
"configuration.SAS.connectionProfiles.profiles.tokenFile": "SAS Viya 令牌文件",
"configuration.SAS.connectionProfiles.profiles.username": "SAS Viya 用户 ID",
"configuration.SAS.session.outputHtml": "启用/禁用 ODS HTML5 输出",
"configuration.SAS.results.html.style": "指定 ODS HTML5 结果的样式。",
"configuration.SAS.results.html.style.(auto)": "让扩展程序选择与颜色主题最匹配的样式。",
"configuration.SAS.results.html.style.(server default)": "默认为 SAS 服务器上配置的样式。",
"configuration.SAS.userProvidedCertificates": "提供受信任的 CA 证书文件",
"notebooks.SAS.htmlRenderer": "SAS HTML 渲染器",
"notebooks.SAS.logRenderer": "SAS 日志渲染器",
Expand Down

0 comments on commit 96116bd

Please sign in to comment.