@@ -6,13 +6,11 @@ import (
6
6
"fmt"
7
7
"io"
8
8
"log"
9
- "runtime"
10
9
"strconv"
11
10
"strings"
12
11
"sync"
13
12
"time"
14
13
15
- "github.com/arduino/arduino-cli/arduino/builder"
16
14
"github.com/arduino/arduino-cli/executils"
17
15
"github.com/arduino/arduino-language-server/sourcemapper"
18
16
"github.com/arduino/arduino-language-server/streams"
@@ -1062,20 +1060,21 @@ func (ls *INOLanguageServer) initializeWorkbench(logger jsonrpc.FunctionLogger,
1062
1060
currCppTextVersion := 0
1063
1061
if params != nil {
1064
1062
logger .Logf (" --> initialize(%s)" , params .RootURI )
1065
- ls .lspInitializeParams = params
1066
1063
ls .sketchRoot = params .RootURI .AsPath ()
1067
1064
ls .sketchName = ls .sketchRoot .Base ()
1065
+ ls .buildSketchCpp = ls .buildSketchRoot .Join (ls .sketchName + ".ino.cpp" )
1066
+
1067
+ ls .lspInitializeParams = params
1068
+ ls .lspInitializeParams .RootPath = ls .buildSketchRoot .String ()
1069
+ ls .lspInitializeParams .RootURI = lsp .NewDocumentURIFromPath (ls .buildSketchRoot )
1068
1070
} else {
1069
1071
logger .Logf (" --> RE-initialize()" )
1070
1072
currCppTextVersion = ls .sketchMapper .CppText .Version
1071
1073
}
1072
1074
1073
- if err := ls .generateBuildEnvironment (logger , ls . buildPath ); err != nil {
1075
+ if err := ls .generateBuildEnvironment (logger ); err != nil {
1074
1076
return err
1075
1077
}
1076
- ls .buildSketchCpp = ls .buildSketchRoot .Join (ls .sketchName + ".ino.cpp" )
1077
- ls .lspInitializeParams .RootPath = ls .buildSketchRoot .String ()
1078
- ls .lspInitializeParams .RootURI = lsp .NewDocumentURIFromPath (ls .buildSketchRoot )
1079
1078
1080
1079
if cppContent , err := ls .buildSketchCpp .ReadFile (); err == nil {
1081
1080
ls .sketchMapper = sourcemapper .CreateInoMapper (cppContent )
@@ -1084,13 +1083,12 @@ func (ls *INOLanguageServer) initializeWorkbench(logger jsonrpc.FunctionLogger,
1084
1083
return errors .WithMessage (err , "reading generated cpp file from sketch" )
1085
1084
}
1086
1085
1087
- canonicalizeCompileCommandsJSON (ls .buildPath )
1088
-
1089
1086
if params == nil {
1090
1087
// If we are restarting re-synchronize clangd
1091
1088
cppURI := lsp .NewDocumentURIFromPath (ls .buildSketchCpp )
1092
1089
1093
- logger .Logf ("LS --> CL NOTIF textDocument/didSave:" )
1090
+ logger .Logf ("Sending 'didSave' notification to Clangd" )
1091
+
1094
1092
didSaveParams := & lsp.DidSaveTextDocumentParams {
1095
1093
TextDocument : lsp.TextDocumentIdentifier {URI : cppURI },
1096
1094
Text : ls .sketchMapper .CppText .Text ,
@@ -1099,6 +1097,8 @@ func (ls *INOLanguageServer) initializeWorkbench(logger jsonrpc.FunctionLogger,
1099
1097
logger .Logf (" error reinitilizing clangd:" , err )
1100
1098
return err
1101
1099
}
1100
+
1101
+ logger .Logf ("Sending 'didChange' notification to Clangd" )
1102
1102
didChangeParams := & lsp.DidChangeTextDocumentParams {
1103
1103
TextDocument : lsp.VersionedTextDocumentIdentifier {
1104
1104
TextDocumentIdentifier : lsp.TextDocumentIdentifier {URI : cppURI },
@@ -1258,36 +1258,6 @@ func (ls *INOLanguageServer) CheckCppIncludesChanges() {
1258
1258
}
1259
1259
}
1260
1260
1261
- func canonicalizeCompileCommandsJSON (compileCommandsDir * paths.Path ) map [string ]bool {
1262
- // Open compile_commands.json and find the main cross-compiler executable
1263
- compileCommandsJSONPath := compileCommandsDir .Join ("compile_commands.json" )
1264
- compileCommands , err := builder .LoadCompilationDatabase (compileCommandsJSONPath )
1265
- if err != nil {
1266
- panic ("could not find compile_commands.json" )
1267
- }
1268
- compilers := map [string ]bool {}
1269
- for i , cmd := range compileCommands .Contents {
1270
- if len (cmd .Arguments ) == 0 {
1271
- panic ("invalid empty argument field in compile_commands.json" )
1272
- }
1273
-
1274
- // clangd requires full path to compiler (including extension .exe on Windows!)
1275
- compilerPath := paths .New (cmd .Arguments [0 ]).Canonical ()
1276
- compiler := compilerPath .String ()
1277
- if runtime .GOOS == "windows" && strings .ToLower (compilerPath .Ext ()) != ".exe" {
1278
- compiler += ".exe"
1279
- }
1280
- compileCommands .Contents [i ].Arguments [0 ] = compiler
1281
-
1282
- compilers [compiler ] = true
1283
- }
1284
-
1285
- // Save back compile_commands.json with OS native file separator and extension
1286
- compileCommands .SaveToFile ()
1287
-
1288
- return compilers
1289
- }
1290
-
1291
1261
func (ls * INOLanguageServer ) didClose (logger jsonrpc.FunctionLogger , inoDidClose * lsp.DidCloseTextDocumentParams ) (* lsp.DidCloseTextDocumentParams , error ) {
1292
1262
inoIdentifier := inoDidClose .TextDocument
1293
1263
if _ , exist := ls .trackedInoDocs [inoIdentifier .URI .AsPath ().String ()]; exist {
@@ -1368,7 +1338,7 @@ func (ls *INOLanguageServer) didChange(logger jsonrpc.FunctionLogger, inoDidChan
1368
1338
1369
1339
cppChanges := []lsp.TextDocumentContentChangeEvent {}
1370
1340
for _ , inoChange := range inoDidChangeParams .ContentChanges {
1371
- cppChangeRange , ok := ls .sketchMapper .InoToCppLSPRangeOk (inoDoc .URI , inoChange .Range )
1341
+ cppChangeRange , ok := ls .sketchMapper .InoToCppLSPRangeOk (inoDoc .URI , * inoChange .Range )
1372
1342
if ! ok {
1373
1343
return nil , errors .Errorf ("invalid change range %s:%s" , inoDoc .URI , inoChange .Range )
1374
1344
}
@@ -1394,7 +1364,7 @@ func (ls *INOLanguageServer) didChange(logger jsonrpc.FunctionLogger, inoDidChan
1394
1364
logger .Logf ("New version:----------+\n " + ls .sketchMapper .CppText .Text + "\n ----------------------" )
1395
1365
1396
1366
cppChanges = append (cppChanges , lsp.TextDocumentContentChangeEvent {
1397
- Range : cppChangeRange ,
1367
+ Range : & cppChangeRange ,
1398
1368
RangeLength : inoChange .RangeLength ,
1399
1369
Text : inoChange .Text ,
1400
1370
})
0 commit comments