@@ -624,23 +624,33 @@ func (handler *InoHandler) didChange(ctx context.Context, req *lsp.DidChangeText
624624
625625 cppChanges := []lsp.TextDocumentContentChangeEvent {}
626626 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+ }
631631
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 {
633647 handler .scheduleRebuildEnvironment ()
634648 }
635649
636650 // log.Println("New version:----------")
637651 // log.Println(handler.sketchMapper.CppText.Text)
638652 // log.Println("----------------------")
639653
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- }
644654 cppChange := lsp.TextDocumentContentChangeEvent {
645655 Range : & cppRange ,
646656 RangeLength : inoChange .RangeLength ,
0 commit comments