@@ -58,6 +58,7 @@ type InoHandler struct {
58
58
buildSketchCpp * paths.Path
59
59
buildSketchCppVersion int
60
60
buildSketchSymbols []lsp.DocumentSymbol
61
+ buildSketchIncludesCanary string
61
62
buildSketchSymbolsCanary string
62
63
buildSketchSymbolsLoad bool
63
64
buildSketchSymbolsCheck bool
@@ -604,28 +605,23 @@ func (handler *InoHandler) refreshCppDocumentSymbols(prefix string) error {
604
605
i ++
605
606
}
606
607
symbols = symbols [:i ]
608
+ handler .buildSketchSymbols = symbols
607
609
608
- canary := ""
609
- for _ , line := range strings .Split (handler .sketchMapper .CppText .Text , "\n " ) {
610
- if strings .Contains (line , "#include <" ) {
611
- canary += line
612
- }
613
- }
610
+ symbolsCanary := ""
614
611
for _ , symbol := range symbols {
615
612
log .Printf (prefix + " symbol: %s %s %s" , symbol .Kind , symbol .Name , symbol .Range )
616
613
if symbolText , err := textutils .ExtractRange (handler .sketchMapper .CppText .Text , symbol .Range ); err != nil {
617
614
log .Printf (prefix + " > invalid range: %s" , err )
618
- canary += "/"
615
+ symbolsCanary += "/"
619
616
} else if end := strings .Index (symbolText , "{" ); end != - 1 {
620
617
log .Printf (prefix + " TRIMMED> %s" , symbolText [:end ])
621
- canary += symbolText [:end ]
618
+ symbolsCanary += symbolText [:end ]
622
619
} else {
623
620
log .Printf (prefix + " > %s" , symbolText )
624
- canary += symbolText
621
+ symbolsCanary += symbolText
625
622
}
626
623
}
627
- handler .buildSketchSymbols = symbols
628
- handler .buildSketchSymbolsCanary = canary
624
+ handler .buildSketchSymbolsCanary = symbolsCanary
629
625
return nil
630
626
}
631
627
@@ -655,6 +651,23 @@ func (handler *InoHandler) CheckCppDocumentSymbols() error {
655
651
return nil
656
652
}
657
653
654
+ func (handler * InoHandler ) CheckCppIncludesChanges () {
655
+ prefix := "INCK--- "
656
+
657
+ includesCanary := ""
658
+ for _ , line := range strings .Split (handler .sketchMapper .CppText .Text , "\n " ) {
659
+ if strings .Contains (line , "#include <" ) {
660
+ includesCanary += line
661
+ }
662
+ }
663
+
664
+ if includesCanary != handler .buildSketchIncludesCanary {
665
+ handler .buildSketchIncludesCanary = includesCanary
666
+ log .Println (prefix + "#include change detected, triggering sketch rebuild!" )
667
+ handler .scheduleRebuildEnvironment ()
668
+ }
669
+ }
670
+
658
671
func examineCompileCommandsJSON (compileCommandsDir * paths.Path ) map [string ]bool {
659
672
// Open compile_commands.json and find the main cross-compiler executable
660
673
compileCommandsJSONPath := compileCommandsDir .Join ("compile_commands.json" )
@@ -833,6 +846,8 @@ func (handler *InoHandler) didChange(ctx context.Context, req *lsp.DidChangeText
833
846
cppChanges = append (cppChanges , cppChange )
834
847
}
835
848
849
+ handler .CheckCppIncludesChanges ()
850
+
836
851
// build a cpp equivalent didChange request
837
852
cppReq := & lsp.DidChangeTextDocumentParams {
838
853
ContentChanges : cppChanges ,
@@ -843,6 +858,7 @@ func (handler *InoHandler) didChange(ctx context.Context, req *lsp.DidChangeText
843
858
Version : handler .sketchMapper .CppText .Version ,
844
859
},
845
860
}
861
+
846
862
return cppReq , nil
847
863
}
848
864
0 commit comments