@@ -624,23 +624,33 @@ func (handler *InoHandler) didChange(ctx context.Context, req *lsp.DidChangeText
624
624
625
625
cppChanges := []lsp.TextDocumentContentChangeEvent {}
626
626
for _ , inoChange := range req .ContentChanges {
627
- dirty := handler .sketchMapper .ApplyTextChange (doc .URI , inoChange )
628
- if dirty {
629
- // TODO: Detect changes in critical lines (for example function definitions )
630
- // and trigger arduino-preprocessing + clangd restart.
627
+ cppRange , ok := handler .sketchMapper .InoToCppLSPRangeOk (doc .URI , * inoChange . Range )
628
+ if ! ok {
629
+ return nil , errors . Errorf ( "invalid change range %s:%s" , doc . URI , * inoChange . Range )
630
+ }
631
631
632
- log .Println ("--! DIRTY CHANGE, force sketch rebuild!" )
632
+ // Detect changes in critical lines (for example function definitions)
633
+ // and trigger arduino-preprocessing + clangd restart.
634
+ dirty := false
635
+ for _ , sym := range handler .buildSketchSymbols {
636
+ if sym .Range .Overlaps (cppRange ) {
637
+ dirty = true
638
+ log .Println ("--! DIRTY CHANGE detected using symbol tables, force sketch rebuild!" )
639
+ break
640
+ }
641
+ }
642
+ if handler .sketchMapper .ApplyTextChange (doc .URI , inoChange ) {
643
+ dirty = true
644
+ log .Println ("--! DIRTY CHANGE detected with sketch mapper, force sketch rebuild!" )
645
+ }
646
+ if dirty {
633
647
handler .scheduleRebuildEnvironment ()
634
648
}
635
649
636
650
// log.Println("New version:----------")
637
651
// log.Println(handler.sketchMapper.CppText.Text)
638
652
// log.Println("----------------------")
639
653
640
- cppRange , ok := handler .sketchMapper .InoToCppLSPRangeOk (doc .URI , * inoChange .Range )
641
- if ! ok {
642
- return nil , errors .Errorf ("invalid change range %s:%s" , doc .URI , * inoChange .Range )
643
- }
644
654
cppChange := lsp.TextDocumentContentChangeEvent {
645
655
Range : & cppRange ,
646
656
RangeLength : inoChange .RangeLength ,
0 commit comments