Skip to content

Commit a7feeba

Browse files
author
Tobias
committed
Pre-release update
1 parent 7779fe3 commit a7feeba

File tree

4 files changed

+46
-25
lines changed

4 files changed

+46
-25
lines changed

CHANGELOG.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@ All notable changes to the "vscode-cppinsights" extension will be documented in
44

55
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
66

7-
## [Unreleased]
8-
9-
- Initial release
7+
## [Pre-release]

README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ For example if there is an image subfolder under your extension project workspac
1111
> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow. -->
1212

1313
## Requirements
14-
1514
This extension requires @andreasfertig's C++ Insights.
1615
C++ Insights can be found here:
1716
https://github.com/andreasfertig/cppinsights.
@@ -22,15 +21,21 @@ Build or download the latest release and specify the path to the cppinsights bin
2221
* `vscode-cppinsights.insightsDiff`: Show C++ insights diff with original
2322

2423
## Extension Settings
25-
2624
This extension contributes the following settings:
2725

2826
* `vscode-cppinsights.path`
29-
* `vscode-cppinsights.buildDirector`
30-
* `vscode-cppinsights.diff`
27+
* `vscode-cppinsights.buildDirectory`
28+
* `vscode-cppinsights.buildDirectoryPrioritizeCMake`
3129
* `vscode-cppinsights.args`
30+
* `vscode-cppinsights.format`
3231
* `vscode-cppinsights.experimental`
3332

33+
## Known Issues
34+
* `vscode-cppinsights.buildDirectoryPrioritizeCMake` is untested
35+
### Formatting (`vscode-cppinsights.format`)
36+
* Enabling the option disables the "preview" property of the output editor
37+
* When using the `insightsDiff` command, the output is not formatted like the original source
38+
3439

3540
<!-- -----------------------------------------------------------------------------------------------------------
3641
## Following extension guidelines

package.json

+13-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"name": "vscode-cppinsights",
33
"displayName": "C++ Insights",
44
"description": "vscode extension for C++ Insights",
5-
"version": "0.0.1",
5+
"version": "0.1.0",
66
"author": {
77
"name": "Tobias Fuchs",
8-
"url": "devtbi.io"
8+
"url": "http://devtbi.io"
99
},
1010
"engines": {
1111
"vscode": "^1.54.0"
@@ -39,26 +39,33 @@
3939
"description": "Build directory of the compilation database.",
4040
"scope": "resource"
4141
},
42+
"vscode-cppinsights.buildDirectoryPrioritizeCMake": {
43+
"type": "boolean",
44+
"default": true,
45+
"description": "If a workspace is active for the source, prioritize the cmake.buildDirectory setting over vscode-cppinsights.buildDirectory.",
46+
"scope": "resource"
47+
},
4248
"vscode-cppinsights.path": {
4349
"type": "string",
4450
"default": "insights",
4551
"description": "Path to the cppinsights executable (insights).",
4652
"scope": "resource"
4753
},
48-
"vscode-cppinsights.diff": {
54+
"vscode-cppinsights.format": {
4955
"type": "boolean",
50-
"description": "Show diff instead of insights output.",
56+
"default": true,
57+
"description": "Format the cppinsights output.",
5158
"scope": "resource"
5259
},
5360
"vscode-cppinsights.args": {
5461
"type": "array",
5562
"default": [],
56-
"description": "Additional arguments. The final call to insights will look like this: <path> <file> -p <buildDirectory> -- <args>",
63+
"description": "Additional arguments. The final call to insights will look like this: '<path> <file> -p <buildDirectory> -- <args>'.",
5764
"scope": "resource"
5865
},
5966
"vscode-cppinsights.experimental": {
6067
"type": "boolean",
61-
"description": "Enable experimental features",
68+
"description": "Enable experimental features, if available.",
6269
"scope": "application"
6370
}
6471
}

src/extension.ts

+23-12
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,18 @@ function executeInsights(show_diff: boolean = false) {
9090
}
9191
}
9292

93+
/**
94+
* Execute insights command
95+
*/
9396
function executeInsights2(show_diff: boolean = false, input_document: vscode.TextDocument, options: vscode.TextEditorOptions, input_path: string) {
9497
let configuration = vscode.workspace.getConfiguration('vscode-cppinsights');
9598

96-
9799
// TODO are code variables resolved, e.g. workspaceFolder?
98100

99101
// discardDescriptor is required, otherwise cmd is not executed b/c file is used by another process
100102
// TODO maybe delete tmp file
101103
tmp.file({ prefix: path.basename(input_path), postfix: '.cpp', keep: false, discardDescriptor: true }, function (err, output_path) {
102-
// TODO improve condition for cmake usage... getWorkspaceFolder b/c default is ${workspaceFolder}/build
103-
const insights_command = createCall(configuration, vscode.workspace.getWorkspaceFolder(input_document.uri) ? vscode.workspace.getConfiguration('cmake').get('buildDirectory') : undefined, input_path, output_path);
104+
const insights_command = createCall(configuration, vscode.workspace.getWorkspaceFolder(input_document.uri) && configuration.get("buildDirectoryPrioritizeCMake") ? vscode.workspace.getConfiguration('cmake').get('buildDirectory') : undefined, input_path, output_path);
104105

105106
console.log("Executing " + JSON.stringify(insights_command));
106107

@@ -154,17 +155,20 @@ function executeInsights2(show_diff: boolean = false, input_document: vscode.Tex
154155
// });
155156
}
156157

158+
/**
159+
* Open the output. Either show it in an editor besides the source, or open a diff.
160+
*/
157161
function openInsightsOutput(input_document: vscode.TextDocument, output_path: string, configuration: vscode.WorkspaceConfiguration, options: vscode.TextEditorOptions, show_diff: boolean) {
158162
let output_uri = vscode.Uri.file(output_path);
159163

160164
// TODO clarify if formatting requires open TextEditor->visually bad, but seems more reliable
161-
let formatting = (doc: vscode.TextDocument) => { format(doc, options, configuration.get("experimental") != undefined ? configuration.get("experimental")! : false) };
165+
let formatting = (doc: vscode.TextDocument) => { configuration.get("format")! ? format(doc, options, configuration.get("experimental")!) : () => { } };
162166

163167

164168
// was { language: vscode.window.activeTextEditor?.document.languageId, content: stdout }
165169
console.log("Openning insights output");
166170
vscode.workspace.openTextDocument(output_uri).then((output_document) => {
167-
if (!configuration.get("diff") && !show_diff) {
171+
if (!show_diff) {
168172
show(output_document, formatting, options);
169173
}
170174
else {
@@ -174,8 +178,11 @@ function openInsightsOutput(input_document: vscode.TextDocument, output_path: st
174178
});
175179
}
176180

181+
/**
182+
* Format the output.
183+
*/
177184
function format(doc: vscode.TextDocument, options: vscode.TextEditorOptions, experimental: boolean) {
178-
let format_options = experimental ? { tabSize: options.tabSize != undefined ? options.tabSize : 4, insertSpaces: options.insertSpaces || false } as vscode.FormattingOptions : { tabSize: 4, insertSpaces: false };
185+
let format_options = { tabSize: options.tabSize != undefined ? options.tabSize : 4, insertSpaces: options.insertSpaces || false } as vscode.FormattingOptions;
179186
console.log("Formatting " + doc.uri + ' ' + JSON.stringify(format_options));
180187

181188
// TODO format options are ignored, only TextEditor options are applied, investigate
@@ -190,12 +197,10 @@ function format(doc: vscode.TextDocument, options: vscode.TextEditorOptions, exp
190197
edit.replace(doc.uri, textEdit.range, textEdit.newText);
191198
}
192199
jobs.push(vscode.workspace.applyEdit(edit));
193-
if (experimental) {
194-
Promise.all(jobs).then(() => {
195-
console.log("Saving format");
196-
doc.save();
197-
});
198-
}
200+
Promise.all(jobs).then(() => {
201+
console.log("Saving format");
202+
doc.save();
203+
});
199204
}
200205
else {
201206
console.log("No format edits");
@@ -206,6 +211,9 @@ function format(doc: vscode.TextDocument, options: vscode.TextEditorOptions, exp
206211
});
207212
}
208213

214+
/**
215+
* Show the output.
216+
*/
209217
function show(doc: vscode.TextDocument, format: (doc: vscode.TextDocument) => void, options: vscode.TextEditorOptions) {
210218
console.log("Showing " + doc.uri);
211219

@@ -216,6 +224,9 @@ function show(doc: vscode.TextDocument, format: (doc: vscode.TextDocument) => vo
216224
});
217225
}
218226

227+
/**
228+
* Diff the source and output.
229+
*/
219230
function diff(left: vscode.TextDocument, right: vscode.TextDocument, format: (doc: vscode.TextDocument) => void) {
220231
console.log("Diffing " + left.uri + ' - ' + right.uri);
221232

0 commit comments

Comments
 (0)