Skip to content

Commit

Permalink
- zmkUpdateBundlesInclude: show virtual doc
Browse files Browse the repository at this point in the history
- export config as env:zmk.xxx
  • Loading branch information
osesov committed Dec 20, 2019
1 parent 69ef150 commit 720bdfd
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
out
node_modules
.vscode-test/
# *.vsix
*.vsix
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "zmk",
"displayName": "zmk",
"description": "Zodiac Make",
"version": "1.0.6",
"version": "1.1.0",
"engines": {
"vscode": "^1.38.0"
},
Expand Down
95 changes: 89 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import * as vscode from 'vscode';
import * as path from 'path';
import * as fs from 'fs';
import { QuickPickItem } from 'vscode';
import { URL } from 'url';

const zmkDocumentScheme = 'zmkdoc';

function exists(file: string): boolean {
return fs.existsSync(file);
Expand All @@ -25,6 +28,11 @@ function findProjectRoot(p: string) : string {
}
}

function hasWorkspace(): boolean {
const workspaceRoot = vscode.workspace.rootPath;
return workspaceRoot !== undefined;
}

function findProjectRootInWorkspace() : string {
let configuration = vscode.workspace.getConfiguration();

Expand Down Expand Up @@ -162,6 +170,39 @@ function getCurrentFile(): string {
return currentFileRelative;
}

//
// function exports zmk settings to environment, since cpptools has no support for ${command:extension.xxx}
// instead in c_cpp_properties use %{env:xxx}
//
function updateCurrentEnvironment()
{
const values : { [key:string]: () => string } = {
'zmk.config': getTargetConfig,
'zmk.target': getNinjaTarget,
'zmk.rootDir': getRootDir,
'zmk.buildDir': getBuildDir,
'zmk.nfsDir': getNfsDir
};

var item;
if (!hasWorkspace()) {
Object.keys(values)
.forEach( item => delete process.env[item]);
return;
}

for (item in values) {
const value = values[item]();
if (!value) {
delete process.env[item];
}
else
{
process.env[item] = value;
}
}
}

// update c_cpp_properties.json file

function zmkUpdateBundlesInclude() {
Expand All @@ -174,8 +215,9 @@ function zmkUpdateBundlesInclude() {
const skipBundles : Array<string> = configuration.get("zmk.excludeBundles") || [];
var configFileName = path.resolve(workspaceRoot, ".vscode", "c_cpp_properties.json");

if (!fs.existsSync(configFileName))
if (!fs.existsSync(configFileName)) {
return;
}

var fileData = fs.readFileSync(configFileName, 'utf8');
var configData = JSON.parse(fileData);
Expand Down Expand Up @@ -218,11 +260,35 @@ function zmkUpdateBundlesInclude() {

var newConfigData = JSON.stringify(configData, null, 4);

var oldFileName = configFileName + ".old";
if (!fs.existsSync(oldFileName)) {
fs.renameSync(configFileName, oldFileName);
}
fs.writeFileSync(configFileName, newConfigData, 'utf8');
const Ok = "Ok";
const ShowConfig = "Show new config";
const Cancel = "Cancel";

vscode.window
.showWarningMessage("Override 'c_cpp_properties.json' file? This would lose comments if any.", Ok, ShowConfig, Cancel)
.then( (outcome) => {
console.log(outcome);

switch(outcome) {
case Ok:
var oldFileName = configFileName + ".old";
if (!fs.existsSync(oldFileName)) {
fs.renameSync(configFileName, oldFileName);
}
fs.writeFileSync(configFileName, newConfigData, 'utf8');
break;
case ShowConfig:
let uri = vscode.Uri.parse(zmkDocumentScheme + ":Virtual document: c_cpp_properties.json?" + newConfigData);
vscode.workspace.openTextDocument(uri)
.then( (doc) =>
vscode.window.showTextDocument(doc),
(error) =>
console.log(error)
);
break;

}
});
}

}
Expand Down Expand Up @@ -253,6 +319,23 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(disposable);
});

// register a content provider for the config document

const myProvider = new class implements vscode.TextDocumentContentProvider {

// emitter and its event
onDidChangeEmitter = new vscode.EventEmitter<vscode.Uri>();
onDidChange = this.onDidChangeEmitter.event;

provideTextDocumentContent(uri: vscode.Uri): string {
return uri.query;
}
};

context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider(zmkDocumentScheme, myProvider));

vscode.workspace.onDidChangeConfiguration(() => updateCurrentEnvironment() );
updateCurrentEnvironment();
}

// this method is called when your extension is deactivated
Expand Down
2 changes: 1 addition & 1 deletion zebra/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"compileCommands": "${command:extension.zmkGetBuildDir}/compile_commands.json"
"compileCommands": "${env:zmk.buildDir}/compile_commands.json"
}
],
"version": 4
Expand Down
6 changes: 3 additions & 3 deletions zebra/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@
// { "name": "V8_FLAGS", "value": "--help" },
// { "name": "V8_FLAGS", "value": "--noconcurrent_recompilation --noconcurrent_osr --noconcurrent_sweeping" },
{ "name": "DFBARGS", "value": "system=x11,module-dir=${command:extension.zmkGetBuildDir}/linux/sysroot/usr/lib/directfb-1.7-8,no-cursor,no-debug,mode=1280x720,depth=32,no-sighandler" },
{ "name": "SKIA_FONTS", "value": "${command:extension.zmkGetNfsDir}/fonts" },
{ "name": "ZEBRA_POLYFILLS_PATH", "value": "${command:extension.zmkGetNfsDir}/polyfills" },
{ "name": "ZEBRA_DEBUG", "value": "!IMAGE_DRAW" },
{ "name": "SKIA_FONTS", "value": "${command:extension.zmkGetBuildDir}/linux/sysroot/home/zodiac/fonts" },
{ "name": "ZEBRA_POLYFILLS_PATH", "value": "${command:extension.zmkGetBuildDir}/linux/sysroot/home/zodiac/polyfills" },
{ "name": "ZEBRA_DEBUG", "value": "!IMAGE_DRAW" }
],
"externalConsole": false,
"MIMode": "gdb",
Expand Down
2 changes: 1 addition & 1 deletion zebra/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"options": {
"cwd": "${command:extension.zmkGetRootDir}"
},
"command": "bash -c './gnb ${command:extension.zmkGetTargetConfig} -- ${command:extension.zmkGetNinjaTarget}; tools/dev/ccmake.sh ${command:extension.zmkGetTargetConfig}'",
"command": "./gnb ${command:extension.zmkGetTargetConfig} -- ${command:extension.zmkGetNinjaTarget}",
"problemMatcher": {
"base": "$gcc",
"fileLocation": [ "relative", "${command:extension.zmkGetBuildDir}" ]
Expand Down
Binary file removed zmk-1.0.6.vsix
Binary file not shown.

0 comments on commit 720bdfd

Please sign in to comment.