Skip to content

Commit

Permalink
feat(vscode): add includepaths option
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyV99 authored and connorjclark committed Aug 6, 2023
1 parent a5a6483 commit 406f41d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
10 changes: 8 additions & 2 deletions vscode-extension/package.json
Expand Up @@ -51,10 +51,16 @@
"default": false,
"description": "Ignores 'CONST_ASSERT' statement errors"
},
"zscript.alwaysInclude": {
"zscript.defaultIncludePaths": {
"scope": "window",
"type": "array",
"default": ["std.zh"],
"default": ["include"],
"description": "Global include paths, to be added to compile attempts."
},
"zscript.defaultIncludeFiles": {
"scope": "window",
"type": "array",
"default": ["include/std.zh"],
"description": "Global includes, to be added to compile attempts."
},
"zscript.trace.server": {
Expand Down
18 changes: 13 additions & 5 deletions vscode-extension/server/src/server.ts
Expand Up @@ -86,7 +86,8 @@ connection.onInitialized(() => {
interface Settings {
installationFolder?: string;
printCompilerOutput?: boolean;
alwaysInclude?: Array<string>;
defaultIncludeFiles?: Array<string>;
defaultIncludePaths?: Array<string>;
ignoreConstAssert?: boolean;
}

Expand Down Expand Up @@ -151,9 +152,7 @@ function fileMatches(f1:string, f2:string)
}

async function processScript(textDocument: TextDocument): Promise<void> {
// In this simple example we get the settings for every validate run.
const settings = await getDocumentSettings(textDocument.uri);
// The validator creates diagnostics for all uppercase words length 2 and more
const text = textDocument.getText();
let includeText = "#option NO_ERROR_HALT on\n#option HEADER_GUARD on\n";

Expand All @@ -173,9 +172,15 @@ async function processScript(textDocument: TextDocument): Promise<void> {
if (!globalTmpDir) {
globalTmpDir = os.tmpdir();
}
if (settings.alwaysInclude)
if (settings.defaultIncludePaths)
{
settings.alwaysInclude.forEach(str =>{
settings.defaultIncludePaths.forEach(str => {
includeText += `#includepath "${str}"\n`;
});
}
if (settings.defaultIncludeFiles)
{
settings.defaultIncludeFiles.forEach(str =>{
includeText += `#include "${str}"\n`;
});
}
Expand All @@ -188,6 +193,9 @@ async function processScript(textDocument: TextDocument): Promise<void> {
fs.writeFileSync(tmpInput, includeText);
fs.writeFileSync(tmpScript, text);
const exe = os.platform() === 'win32' ? './zscript.exe' : './zscript';
if (settings.printCompilerOutput) {
console.log(`Attempting to compile buffer:\n-----\n${includeText}\n-----`);
}
try {
const args = [
'-unlinked',
Expand Down

0 comments on commit 406f41d

Please sign in to comment.