1
1
import * as ccp from "cocopa" ;
2
2
import * as path from "path" ;
3
+
3
4
import * as constants from "../common/constants" ;
4
5
import { arduinoChannel } from "../common/outputChannel" ;
5
6
import { ArduinoWorkspace } from "../common/workspace" ;
6
7
import { DeviceContext } from "../deviceContext" ;
8
+
7
9
import { VscodeSettings } from "./vscodeSettings" ;
8
10
11
+ export interface ICoCoPaContext {
12
+ callback : ( s : string ) => void ;
13
+ conclude : ( ) => void ;
14
+ } ;
15
+
16
+ /**
17
+ * Returns true if the combination of global enable/disable and project
18
+ * specific override enable the auto-generation of the IntelliSense
19
+ * configuration.
20
+ */
21
+ export function isCompilerParserEnabled ( dc ?: DeviceContext ) {
22
+ if ( ! dc ) {
23
+ dc = DeviceContext . getInstance ( ) ;
24
+ }
25
+ const globalDisable = VscodeSettings . getInstance ( ) . disableIntelliSenseAutoGen ;
26
+ const projectSetting = dc . disableIntelliSenseAutoGen ;
27
+ return projectSetting !== "disable" && ! globalDisable ||
28
+ projectSetting === "enable" ;
29
+ }
30
+
9
31
/**
10
32
* Creates a context which is used for compiler command parsing
11
33
* during building (verify, upload, ...).
@@ -16,61 +38,55 @@ import { VscodeSettings } from "./vscodeSettings";
16
38
*
17
39
* @param dc The device context of the caller.
18
40
*/
19
- export function makeCompilerParserContext ( dc : DeviceContext )
20
- : { callback : ( s : string ) => void ; conclude : ( ) => void ; } {
21
-
22
- const globalDisable = VscodeSettings . getInstance ( ) . disableIntelliSenseAutoGen ;
23
- const project = dc . disableIntelliSenseAutoGen ;
24
-
25
- if ( project !== "disable" && ! globalDisable ||
26
- project === "enable" ) {
41
+ export function makeCompilerParserContext ( dc : DeviceContext ) : ICoCoPaContext {
27
42
28
- const engines = makeCompilerParserEngines ( dc ) ;
29
- const runner = new ccp . Runner ( engines ) ;
43
+ const engines = makeCompilerParserEngines ( dc ) ;
44
+ const runner = new ccp . Runner ( engines ) ;
30
45
31
- // set up the function to be called after parsing
32
- const _conclude = ( ) => {
33
- if ( ! runner . result ) {
34
- arduinoChannel . warning ( "Failed to generate IntelliSense configuration." ) ;
35
- return ;
36
- }
37
- const pPath = path . join ( ArduinoWorkspace . rootPath , constants . CPP_CONFIG_FILE ) ;
38
- // TODO: check what kind of result we've got: gcc or other architecture:
39
- // and instantiate content accordingly (to be implemented within cocopa)
40
- const content = new ccp . CCppPropertiesContentResult ( runner . result ,
41
- "Arduino" ,
42
- ccp . CCppPropertiesISMode . Gcc_X64 ,
43
- ccp . CCppPropertiesCStandard . C11 ,
44
- // as of 1.8.11 arduino is on C++11
45
- ccp . CCppPropertiesCppStandard . Cpp11 ) ;
46
- try {
47
- const prop = new ccp . CCppProperties ( ) ;
48
- prop . read ( pPath ) ;
49
- prop . merge ( content , ccp . CCppPropertiesMergeMode . ReplaceSameNames ) ;
50
- if ( prop . write ( pPath ) ) {
51
- arduinoChannel . info ( "IntelliSense configuration updated." ) ;
52
- } else {
53
- arduinoChannel . info ( "IntelliSense configuration already up to date." ) ;
54
- }
55
- } catch ( e ) {
56
- // tslint:disable-next-line: no-console
57
- console . log ( e ) ;
46
+ // Set up the callback to be called after parsing
47
+ const _conclude = ( ) => {
48
+ if ( ! runner . result ) {
49
+ arduinoChannel . warning ( "Failed to generate IntelliSense configuration." ) ;
50
+ return ;
51
+ }
52
+ const pPath = path . join ( ArduinoWorkspace . rootPath , constants . CPP_CONFIG_FILE ) ;
53
+ // TODO: check what kind of result we've got: gcc or other architecture:
54
+ // and instantiate content accordingly (to be implemented within cocopa)
55
+ const content = new ccp . CCppPropertiesContentResult ( runner . result ,
56
+ "Arduino" ,
57
+ ccp . CCppPropertiesISMode . Gcc_X64 ,
58
+ ccp . CCppPropertiesCStandard . C11 ,
59
+ // as of 1.8.11 arduino is on C++11
60
+ ccp . CCppPropertiesCppStandard . Cpp11 ) ;
61
+ try {
62
+ const prop = new ccp . CCppProperties ( ) ;
63
+ prop . read ( pPath ) ;
64
+ prop . merge ( content , ccp . CCppPropertiesMergeMode . ReplaceSameNames ) ;
65
+ if ( prop . write ( pPath ) ) {
66
+ arduinoChannel . info ( "IntelliSense configuration updated." ) ;
67
+ } else {
68
+ arduinoChannel . info ( "IntelliSense configuration already up to date." ) ;
58
69
}
59
- } ;
60
- return {
61
- callback : runner . callback ( ) ,
62
- conclude : _conclude ,
70
+ } catch ( e ) {
71
+ const estr = JSON . stringify ( e ) ;
72
+ arduinoChannel . error ( `Failed to read or write IntelliSense configuration: ${ estr } ` ) ;
63
73
}
64
- }
74
+ } ;
65
75
return {
66
- callback : undefined ,
67
- conclude : undefined ,
76
+ callback : runner . callback ( ) ,
77
+ conclude : _conclude ,
68
78
}
69
79
} ;
70
80
71
81
/**
82
+ * Assembles compiler parser engines which then will be used to find the main
83
+ * sketch's compile command and parse the infomation from it required for
84
+ * assembling an IntelliSense configuration from it.
85
+ *
86
+ * It could return multiple engines for different compilers or - if necessary -
87
+ * return specialized engines based on the current board architecture.
72
88
*
73
- * @param dc
89
+ * @param dc Current device context used to generate the engines.
74
90
*/
75
91
function makeCompilerParserEngines ( dc : DeviceContext ) {
76
92
0 commit comments