@@ -40,10 +40,34 @@ func Setup(cliPath string, clangdPath string, _enableLogging bool, _asyncProcess
4040// CLangdStarter starts clangd and returns its stdin/out/err
4141type CLangdStarter func () (stdin io.WriteCloser , stdout io.ReadCloser , stderr io.ReadCloser )
4242
43+ // InoHandler is a JSON-RPC handler that delegates messages to clangd.
44+ type InoHandler struct {
45+ StdioConn * jsonrpc2.Conn
46+ ClangdConn * jsonrpc2.Conn
47+ lspInitializeParams * lsp.InitializeParams
48+ buildPath * paths.Path
49+ buildSketchRoot * paths.Path
50+ buildSketchCpp * paths.Path
51+ buildSketchCppVersion int
52+ buildSketchSymbols []lsp.DocumentSymbol
53+ buildSketchSymbolsLoad bool
54+ buildSketchSymbolsCheck bool
55+ rebuildSketchDeadline * time.Time
56+ rebuildSketchDeadlineMutex sync.Mutex
57+ sketchRoot * paths.Path
58+ sketchName string
59+ sketchMapper * sourcemapper.InoMapper
60+ sketchTrackedFilesCount int
61+ docs map [lsp.DocumentURI ]* lsp.TextDocumentItem
62+
63+ config lsp.BoardConfig
64+ synchronizer Synchronizer
65+ }
66+
4367// NewInoHandler creates and configures an InoHandler.
4468func NewInoHandler (stdio io.ReadWriteCloser , board lsp.Board ) * InoHandler {
4569 handler := & InoHandler {
46- trackedFiles : map [lsp.DocumentURI ]* lsp.TextDocumentItem {},
70+ docs : map [lsp.DocumentURI ]* lsp.TextDocumentItem {},
4771 config : lsp.BoardConfig {
4872 SelectedBoard : board ,
4973 },
@@ -66,30 +90,6 @@ func NewInoHandler(stdio io.ReadWriteCloser, board lsp.Board) *InoHandler {
6690 return handler
6791}
6892
69- // InoHandler is a JSON-RPC handler that delegates messages to clangd.
70- type InoHandler struct {
71- StdioConn * jsonrpc2.Conn
72- ClangdConn * jsonrpc2.Conn
73- lspInitializeParams * lsp.InitializeParams
74- buildPath * paths.Path
75- buildSketchRoot * paths.Path
76- buildSketchCpp * paths.Path
77- buildSketchCppVersion int
78- buildSketchSymbols []lsp.DocumentSymbol
79- buildSketchSymbolsLoad bool
80- buildSketchSymbolsCheck bool
81- rebuildSketchDeadline * time.Time
82- rebuildSketchDeadlineMutex sync.Mutex
83- sketchRoot * paths.Path
84- sketchName string
85- sketchMapper * sourcemapper.InoMapper
86- sketchTrackedFilesCount int
87- trackedFiles map [lsp.DocumentURI ]* lsp.TextDocumentItem
88-
89- config lsp.BoardConfig
90- synchronizer Synchronizer
91- }
92-
9393// FileData gathers information on a .ino source file.
9494type FileData struct {
9595 sourceText string
@@ -504,7 +504,7 @@ func startClangd(compileCommandsDir, sketchCpp *paths.Path) (io.WriteCloser, io.
504504func (handler * InoHandler ) didOpen (ctx context.Context , params * lsp.DidOpenTextDocumentParams ) (* lsp.DidOpenTextDocumentParams , error ) {
505505 // Add the TextDocumentItem in the tracked files list
506506 doc := params .TextDocument
507- handler .trackedFiles [doc .URI ] = & doc
507+ handler .docs [doc .URI ] = & doc
508508
509509 // If we are tracking a .ino...
510510 if doc .URI .AsPath ().Ext () == ".ino" {
@@ -534,7 +534,7 @@ func (handler *InoHandler) didOpen(ctx context.Context, params *lsp.DidOpenTextD
534534func (handler * InoHandler ) didChange (ctx context.Context , req * lsp.DidChangeTextDocumentParams ) (* lsp.DidChangeTextDocumentParams , error ) {
535535 doc := req .TextDocument
536536
537- trackedDoc , ok := handler .trackedFiles [doc .URI ]
537+ trackedDoc , ok := handler .docs [doc .URI ]
538538 if ! ok {
539539 return nil , unknownURI (doc .URI )
540540 }
@@ -1045,7 +1045,7 @@ func (handler *InoHandler) FromClangd(ctx context.Context, connection *jsonrpc2.
10451045 // XXX: Optimize this to publish "empty diagnostics" only to .ino that are
10461046 // currently showing previous diagnostics.
10471047
1048- for sourceURI := range handler .trackedFiles {
1048+ for sourceURI := range handler .docs {
10491049 msg := lsp.PublishDiagnosticsParams {
10501050 URI : sourceURI ,
10511051 Diagnostics : []lsp.Diagnostic {},
0 commit comments