29
29
30
30
#include " CommandLine.hpp"
31
31
#include " Config.hpp"
32
+ #include " utils.hpp"
32
33
33
34
#include < iostream>
34
-
35
- using namespace std ;
35
+ #include < sstream>
36
36
37
37
bool debugOutput;
38
38
bool outputDiagnostics;
39
39
bool outputOnlyNeededPrototypes;
40
40
bool outputPreprocessedSketch = true ;
41
41
42
+ // Code completion parameters
43
+ bool outputCodeCompletions;
44
+ string codeCompleteFilename;
45
+ int codeCompleteLine;
46
+ int codeCompleteCol;
47
+
42
48
static cl::OptionCategory arduinoToolCategory (" Arduino options" );
43
49
// TODO: add complete help
44
50
static cl::extrahelp arduinoHelp (" \n "
@@ -49,6 +55,7 @@ static cl::extrahelp commonHelp(CommonOptionsParser::HelpMessage);
49
55
static cl::opt<bool > debugOutputOpt (" debug" );
50
56
static cl::opt<bool > outputOnlyNeededPrototypesOpt (" output-only-needed-prototypes" );
51
57
static cl::opt<bool > outputDiagnosticsOpt (" output-diagnostics" );
58
+ static cl::opt<string> outputCodeCompletionsOpt (" output-code-completions" );
52
59
53
60
static void printVersion () {
54
61
cout << " Arduino (https://www.arduino.cc/):\n " ;
@@ -68,14 +75,39 @@ CommonOptionsParser doCommandLineParsing(int argc, const char **argv) {
68
75
outputDiagnosticsOpt.setInitialValue (false );
69
76
outputDiagnosticsOpt.setDescription (" Output diagnostics (warnings/errors) in json format" );
70
77
78
+ outputCodeCompletionsOpt.setCategory (arduinoToolCategory);
79
+ outputCodeCompletionsOpt.setInitialValue (" " );
80
+ outputCodeCompletionsOpt.setDescription (
81
+ " Output code completions (suggestions) in json format.\n "
82
+ " This option requires the cursor position in the format \" filename:line:col\" " );
83
+
71
84
cl::AddExtraVersionPrinter (printVersion);
72
85
73
86
CommonOptionsParser optParser (argc, argv, arduinoToolCategory);
74
87
88
+ /* Parse outputCodeCompletion parameter */
89
+ if (outputCodeCompletionsOpt.getValue () != " " ) {
90
+ vector<string> spl = split (outputCodeCompletionsOpt.getValue (), ' :' );
91
+ if (spl.size () != 3 ) {
92
+ cerr << " code completion requires parameter in the form \" filename:line:col\"\n " ;
93
+ exit (1 );
94
+ }
95
+ codeCompleteFilename = spl[0 ];
96
+ if (!stringToInt (spl[1 ], &codeCompleteLine)) {
97
+ cerr << " code completion requires 'line' to be a positive integer parameter in the form \" filename:line:col\"\n " ;
98
+ exit (1 );
99
+ }
100
+ if (!stringToInt (spl[2 ], &codeCompleteCol)) {
101
+ cerr << " code completion requires 'col' to be a positive integer parameter in the form \" filename:line:col\"\n " ;
102
+ exit (1 );
103
+ }
104
+ outputCodeCompletions = true ;
105
+ }
106
+
75
107
debugOutput = debugOutputOpt.getValue ();
76
108
outputOnlyNeededPrototypes = outputOnlyNeededPrototypesOpt.getValue ();
77
109
outputDiagnostics = outputDiagnosticsOpt.getValue ();
78
- if (outputDiagnostics) {
110
+ if (outputDiagnostics || outputCodeCompletions ) {
79
111
outputPreprocessedSketch = false ;
80
112
}
81
113
return optParser;
0 commit comments