@@ -6,7 +6,7 @@ import path = require('path');
6
6
7
7
export function activate ( context : vscode . ExtensionContext ) {
8
8
9
- console . log ( 'Activating "cppinsights- vscode"' ) ;
9
+ console . log ( 'Activating "vscode-cppinsights "' ) ;
10
10
11
11
12
12
registerCommands ( context ) ;
@@ -16,35 +16,33 @@ export function activate(context: vscode.ExtensionContext) {
16
16
* Register all commands
17
17
*/
18
18
function registerCommands ( context : vscode . ExtensionContext ) {
19
- vscode . commands . registerTextEditorCommand ( 'cppinsights- vscode.insights' , ( ) => {
19
+ vscode . commands . registerTextEditorCommand ( 'vscode-cppinsights .insights' , ( ) => {
20
20
executeInsights ( ) ;
21
21
} ) ;
22
22
23
- vscode . commands . registerTextEditorCommand ( 'cppinsights- vscode.insightsDiff' , ( ) => {
23
+ vscode . commands . registerTextEditorCommand ( 'vscode-cppinsights .insightsDiff' , ( ) => {
24
24
executeInsights ( true ) ;
25
25
} ) ;
26
26
// TODO format, diff as parameter to command instead of extra commands, no-build-dir
27
-
28
- // TODO check register result
29
27
}
30
28
31
29
/**
32
30
* Create the skeleton insights command from the configuration
33
31
*/
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 ) [ ] } {
36
33
let build_dir = cmake_build_dir || config . get ( 'buildDirectory' ) ;
37
34
38
35
if ( ! config . get ( 'path' ) ) {
39
- vscode . window . showErrorMessage ( 'Missing value for cppinsights- vscode.path' ) ;
36
+ vscode . window . showErrorMessage ( 'Missing value for vscode-cppinsights .path' ) ;
40
37
throw vscode . CancellationError ;
41
38
}
42
39
43
- let args : string [ ] = [ ] ;
44
- if ( build_dir )
40
+ let args : string [ ] = [ filePath ] ;
41
+ if ( build_dir && build_dir . length > 0 )
45
42
args . push ( "-p=\"" + build_dir + "\"" ) ;
46
43
47
44
if ( config . get < string [ ] > ( 'args' ) ) {
45
+ args . push ( "--" ) ;
48
46
args = [ ...args , ...config . get < string [ ] > ( 'args' ) ! ] ;
49
47
}
50
48
@@ -53,12 +51,18 @@ function createExecutableBase(config: vscode.WorkspaceConfiguration, cmake_build
53
51
} ;
54
52
}
55
53
54
+ export function callToString ( insights_call : { path : string , args : ( string ) [ ] } ) : string {
55
+ return insights_call . path + ' ' + insights_call . args . join ( ' ' ) ;
56
+ }
57
+
56
58
/**
57
59
* Execute insights command
58
60
*/
59
61
function executeInsights ( show_diff : boolean = false ) {
60
- let configuration = vscode . workspace . getConfiguration ( 'cppinsights- vscode' ) ;
62
+ let configuration = vscode . workspace . getConfiguration ( 'vscode-cppinsights ' ) ;
61
63
64
+ // TODO on save
65
+ // TODO formatter use configured settings
62
66
63
67
// TODO Impl as TextDocumentProvider
64
68
// TODO QuickDiffProvider?
@@ -71,17 +75,16 @@ function executeInsights(show_diff: boolean = false) {
71
75
let input_document = input_editor ! . document ;
72
76
73
77
// 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 ! ) ;
76
79
77
80
console . log ( "Executing " + JSON . stringify ( insights_command ) ) ;
78
81
79
82
// TODO code variables are probably not resloved, use vscode Task interface
80
83
// 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 ) ;
82
85
child . exec ( exec_command , ( error : child . ExecException | null , stdout : string , stderr : string ) => {
83
86
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 ) ;
85
88
console . error ( error ) ;
86
89
console . error ( stderr ) ;
87
90
return ;
@@ -107,7 +110,7 @@ function executeInsights(show_diff: boolean = false) {
107
110
} ) ;
108
111
}
109
112
else {
110
- diff ( input_document . uri , output_document . uri )
113
+ diff ( input_document . uri , output_document . uri ) ;
111
114
}
112
115
} ) ;
113
116
} ) ;
@@ -120,7 +123,7 @@ function executeInsights(show_diff: boolean = false) {
120
123
}
121
124
122
125
function format ( uri : vscode . Uri ) {
123
- console . log ( "Formatting document" )
126
+ console . log ( "Formatting document" ) ;
124
127
125
128
// TODO read format options form settings
126
129
vscode . commands . executeCommand ( 'vscode.executeFormatDocumentProvider' , uri , { tabSize : 4 , insertSpaces : false } ) . then ( ( textEdits ) => {
0 commit comments