Skip to content

Commit d6380e8

Browse files
Tobiasdevtbi
Tobias
authored andcommitted
Merge dev state to main (#1)
1 parent 78ec0a3 commit d6380e8

File tree

8 files changed

+101
-41
lines changed

8 files changed

+101
-41
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,8 @@ dist
105105

106106
# TernJS port file
107107
.tern-port
108+
109+
# Misc
110+
.vscode-test/
111+
package-lock.json
112+
.eslintrc.json

.vscode/launch.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"type": "extensionHost",
2323
"request": "launch",
2424
"args": [
25+
"${workspaceFolder}/src/test/suite/test.cpp",
2526
"--extensionDevelopmentPath=${workspaceFolder}",
2627
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
2728
],
@@ -31,4 +32,4 @@
3132
"preLaunchTask": "${defaultBuildTask}"
3233
}
3334
]
34-
}
35+
}

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Change Log
22

3-
All notable changes to the "cppinsights-vscode" extension will be documented in this file.
3+
All notable changes to the "vscode-cppinsights" extension will be documented in this file.
44

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

README.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,20 @@ This extension requires C++ Insights of @andreasfertig.
1616
C++ Insights can be found here:
1717
https://github.com/andreasfertig/cppinsights
1818
Build or download the latest release.
19-
Specify the directory to cppinsights binary in (link to settings) `cppinsights-vscode.path`.
19+
Specify the directory to cppinsights binary in (link to settings) `vscode-cppinsights.path`.
20+
21+
## Commands
22+
* `vscode-cppinsights.insights`: Show C++ insights
23+
* `vscode-cppinsights.insightsDiff`: Show C++ insights diff with original
2024

2125
## Extension Settings
2226

2327
This extension contributes the following settings:
2428

25-
* `cppinsights-vscode.path`
26-
* `cppinsights-vscode.buildDirector`
27-
* `cppinsights-vscode.diff`
28-
* `cppinsights-vscode.args`
29+
* `vscode-cppinsights.path`
30+
* `vscode-cppinsights.buildDirector`
31+
* `vscode-cppinsights.diff`
32+
* `vscode-cppinsights.args`
2933

3034

3135
<!-- -----------------------------------------------------------------------------------------------------------

package.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "cppinsights-vscode",
2+
"name": "vscode-cppinsights",
33
"displayName": "C++ Insights",
44
"description": "vscode extension for C++ Insights",
55
"version": "0.0.1",
@@ -14,46 +14,46 @@
1414
"Other"
1515
],
1616
"activationEvents": [
17-
"onCommand:cppinsights-vscode.insights",
18-
"onCommand:cppinsights-vscode.insightsDiff"
17+
"onCommand:vscode-cppinsights.insights",
18+
"onCommand:vscode-cppinsights.insightsDiff"
1919
],
2020
"main": "./out/extension.js",
2121
"contributes": {
2222
"commands": [
2323
{
24-
"command": "cppinsights-vscode.insights",
24+
"command": "vscode-cppinsights.insights",
2525
"title": "Show C++ insights"
2626
},
2727
{
28-
"command": "cppinsights-vscode.insightsDiff",
28+
"command": "vscode-cppinsights.insightsDiff",
2929
"title": "Show C++ insights diff with original"
3030
}
3131
],
3232
"configuration": [
3333
{
3434
"title": "C++ insights",
3535
"properties": {
36-
"cppinsights-vscode.buildDirectory": {
36+
"vscode-cppinsights.buildDirectory": {
3737
"type": "string",
3838
"default": [],
39-
"description": "Build directory of the compilation database",
39+
"description": "Build directory of the compilation database.",
4040
"scope": "resource"
4141
},
42-
"cppinsights-vscode.path": {
42+
"vscode-cppinsights.path": {
4343
"type": "string",
4444
"default": "insights",
45-
"description": "Path to the cppinsights executable (insights)",
45+
"description": "Path to the cppinsights executable (insights).",
4646
"scope": "resource"
4747
},
48-
"cppinsights-vscode.diff": {
48+
"vscode-cppinsights.diff": {
4949
"type": "boolean",
50-
"description": "Show diff instead of insights output",
50+
"description": "Show diff instead of insights output.",
5151
"scope": "resource"
5252
},
53-
"cppinsights-vscode.args": {
53+
"vscode-cppinsights.args": {
5454
"type": "array",
5555
"default": [],
56-
"description": "Additional arguments",
56+
"description": "Additional arguments. The final call to insights will look like this: <path> <file> -p <buildDirectory> -- <args>",
5757
"scope": "resource"
5858
}
5959
}

src/extension.ts

+20-17
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import path = require('path');
66

77
export function activate(context: vscode.ExtensionContext) {
88

9-
console.log('Activating "cppinsights-vscode"');
9+
console.log('Activating "vscode-cppinsights"');
1010

1111

1212
registerCommands(context);
@@ -16,35 +16,33 @@ export function activate(context: vscode.ExtensionContext) {
1616
* Register all commands
1717
*/
1818
function registerCommands(context: vscode.ExtensionContext) {
19-
vscode.commands.registerTextEditorCommand('cppinsights-vscode.insights', () => {
19+
vscode.commands.registerTextEditorCommand('vscode-cppinsights.insights', () => {
2020
executeInsights();
2121
});
2222

23-
vscode.commands.registerTextEditorCommand('cppinsights-vscode.insightsDiff', () => {
23+
vscode.commands.registerTextEditorCommand('vscode-cppinsights.insightsDiff', () => {
2424
executeInsights(true);
2525
});
2626
// TODO format, diff as parameter to command instead of extra commands, no-build-dir
27-
28-
// TODO check register result
2927
}
3028

3129
/**
3230
* Create the skeleton insights command from the configuration
3331
*/
34-
function createExecutableBase(config: vscode.WorkspaceConfiguration, cmake_build_dir: string | undefined): { path: string, args: (string)[] } {
35-
32+
export function createCall(config: vscode.WorkspaceConfiguration, cmake_build_dir: string | undefined, filePath: string): { path: string, args: (string)[] } {
3633
let build_dir = cmake_build_dir || config.get('buildDirectory');
3734

3835
if (!config.get('path')) {
39-
vscode.window.showErrorMessage('Missing value for cppinsights-vscode.path');
36+
vscode.window.showErrorMessage('Missing value for vscode-cppinsights.path');
4037
throw vscode.CancellationError;
4138
}
4239

43-
let args: string[] = [];
44-
if (build_dir)
40+
let args: string[] = [filePath];
41+
if (build_dir && build_dir.length > 0)
4542
args.push("-p=\"" + build_dir + "\"");
4643

4744
if (config.get<string[]>('args')) {
45+
args.push("--");
4846
args = [...args, ...config.get<string[]>('args')!];
4947
}
5048

@@ -53,12 +51,18 @@ function createExecutableBase(config: vscode.WorkspaceConfiguration, cmake_build
5351
};
5452
}
5553

54+
export function callToString(insights_call: { path: string, args: (string)[] }): string {
55+
return insights_call.path + ' ' + insights_call.args.join(' ');
56+
}
57+
5658
/**
5759
* Execute insights command
5860
*/
5961
function executeInsights(show_diff: boolean = false) {
60-
let configuration = vscode.workspace.getConfiguration('cppinsights-vscode');
62+
let configuration = vscode.workspace.getConfiguration('vscode-cppinsights');
6163

64+
// TODO on save
65+
// TODO formatter use configured settings
6266

6367
// TODO Impl as TextDocumentProvider
6468
// TODO QuickDiffProvider?
@@ -71,17 +75,16 @@ function executeInsights(show_diff: boolean = false) {
7175
let input_document = input_editor!.document;
7276

7377
// TODO improve condition for cmake usage... getWorkspaceFolder b/c default is ${workspaceFolder}/build
74-
let insights_command = createExecutableBase(configuration, vscode.workspace.getWorkspaceFolder(input_document.uri) ? vscode.workspace.getConfiguration('cmake').get('buildDirectory') : undefined);
75-
insights_command.args.push(input_document.fileName!);
78+
let insights_command = createCall(configuration, vscode.workspace.getWorkspaceFolder(input_document.uri) ? vscode.workspace.getConfiguration('cmake').get('buildDirectory') : undefined, input_document.fileName!);
7679

7780
console.log("Executing " + JSON.stringify(insights_command));
7881

7982
// TODO code variables are probably not resloved, use vscode Task interface
8083
// TODO use execFile or sth else which allows for passing args as string[]
81-
const exec_command = insights_command.path + ' ' + insights_command.args.join(' ');
84+
const exec_command = callToString(insights_command);
8285
child.exec(exec_command, (error: child.ExecException | null, stdout: string, stderr: string) => {
8386
if (error) {
84-
vscode.window.showErrorMessage('insights failed:\n' + exec_command + '\n' + stderr);
87+
vscode.window.showErrorMessage('insights failed:\n' + exec_command + '\n' + stderr + '\n' + stdout);
8588
console.error(error);
8689
console.error(stderr);
8790
return;
@@ -107,7 +110,7 @@ function executeInsights(show_diff: boolean = false) {
107110
});
108111
}
109112
else {
110-
diff(input_document.uri, output_document.uri)
113+
diff(input_document.uri, output_document.uri);
111114
}
112115
});
113116
});
@@ -120,7 +123,7 @@ function executeInsights(show_diff: boolean = false) {
120123
}
121124

122125
function format(uri: vscode.Uri) {
123-
console.log("Formatting document")
126+
console.log("Formatting document");
124127

125128
// TODO read format options form settings
126129
vscode.commands.executeCommand('vscode.executeFormatDocumentProvider', uri, { tabSize: 4, insertSpaces: false }).then((textEdits) => {

src/test/suite/extension.test.ts

+36-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,47 @@
11
import * as assert from 'assert';
2+
import * as child from 'child_process';
23

34
// You can import and use all API from the 'vscode' module
45
// as well as import your extension to test it
56
import * as vscode from 'vscode';
6-
// import * as myExtension from '../../extension';
7+
import * as ins from '../../extension';
8+
9+
export async function getExtension() {
10+
const ext = vscode.extensions.getExtension('vscode-cppinsights');
11+
if (!ext) {
12+
throw new Error('Extension doesn\'t exist');
13+
}
14+
return ext.isActive ? Promise.resolve(ext.exports) : ext.activate();
15+
}
716

817
suite('Extension Test Suite', () => {
918
vscode.window.showInformationMessage('Start all tests.');
1019

11-
test('Sample test', () => {
12-
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
13-
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
20+
// test('Load extension', () => {
21+
// getExtension();
22+
// });
23+
24+
test('Execute command', () => {
25+
return vscode.commands.executeCommand('vscode-cppinsights.insights').then(() => {
26+
console.log("Command success");
27+
}, (rejection_reason) => {
28+
assert.fail("Unable to run command");
29+
});
30+
});
31+
32+
test('Run executable', () => {
33+
let configuration = vscode.workspace.getConfiguration('vscode-cppinsights');
34+
35+
let uri = vscode.window.visibleTextEditors[0].document.uri;
36+
37+
let insights_command = ins.createCall(configuration, undefined, uri.path);
38+
39+
const exec_command = ins.callToString(insights_command);
40+
return child.exec(exec_command, (error: child.ExecException | null, stdout: string, stderr: string) => {
41+
if (error) {
42+
assert.fail("Unable to run insights");
43+
}
44+
});
1445
});
46+
1547
});

src/test/suite/test.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <array>
2+
#include <iostream>
3+
4+
int main()
5+
{
6+
std::cout << "showcase of cpp-insights vscode extension";
7+
8+
std::array<char, 10> arr = {2, 4, 6, 8, '\0', '\0', '\0', '\0', '\0', '\0'};
9+
10+
for(const char& c : arr) {
11+
printf("c=%c\n", c);
12+
}
13+
14+
return 0;
15+
}

0 commit comments

Comments
 (0)