From 30a70ffa4b99b0c3cc5d2a271d15fbaab6a49c5f Mon Sep 17 00:00:00 2001 From: Eran Ifrah Date: Sun, 31 Jan 2021 21:49:41 +0200 Subject: [PATCH] LSP: when openening opening a header file, pass to the LSP the implemetation file as well --- Plugin/LanguageServerProtocol.cpp | 35 +++++++++++++------------------ 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/Plugin/LanguageServerProtocol.cpp b/Plugin/LanguageServerProtocol.cpp index 701cc85872..925b336671 100644 --- a/Plugin/LanguageServerProtocol.cpp +++ b/Plugin/LanguageServerProtocol.cpp @@ -304,27 +304,6 @@ void LanguageServerProtocol::FindDefinition(IEditor* editor) CHECK_PTR_RET(editor); CHECK_COND_RET(ShouldHandleFile(editor)); - // clangd will return the match for the declaration incase it never parsed the implementation file - // so we apply this logic: - // - if the file is header then: - // - find all possible implementation files (based on file extension) - // - check to see if these files were parsed already - // - for every file that was not parsed, send SendOpenRequest request - - wxArrayString others; - if(FindImplFile(editor->GetFileName().GetFullPath(), others)) { - for(const wxString& cppFile : others) { - if(m_filesSent.count(cppFile) == 0 && ShouldHandleFile(cppFile)) { - // we never parsed this file before - clDEBUG() << "Before calling 'FindDefintion' parsing implementation file:" << cppFile << endl; - std::string fileContent; - if(FileUtils::ReadFileContentRaw(cppFile, fileContent)) { - SendOpenRequest(cppFile, fileContent, GetLanguageId(fileContent)); - } - } - } - } - // If the editor is modified, we need to tell the LSP to reparse the source file const wxFileName& filename = editor->GetFileName(); if(m_filesSent.count(filename.GetFullPath()) && editor->IsModified()) { @@ -453,6 +432,20 @@ void LanguageServerProtocol::OpenEditor(IEditor* editor) clDEBUG() << "OpenEditor->SendChangeRequest called for:" << editor->GetFileName().GetFullName(); SendChangeRequest(editor->GetFileName(), fileContent); } else { + // If we are about to load a header file, also pass clangd the implementation(s) file + wxArrayString others; + if(FindImplFile(editor->GetFileName().GetFullPath(), others)) { + for(const wxString& cppFile : others) { + if(m_filesSent.count(cppFile) == 0 && ShouldHandleFile(cppFile)) { + // we never parsed this file before + clDEBUG() << "OpenEditor->SendOpenRequest called for:" << cppFile << endl; + std::string fileContent; + if(FileUtils::ReadFileContentRaw(cppFile, fileContent)) { + SendOpenRequest(cppFile, fileContent, GetLanguageId(fileContent)); + } + } + } + } clDEBUG() << "OpenEditor->SendOpenRequest called for:" << editor->GetFileName().GetFullName(); SendOpenRequest(editor->GetFileName(), fileContent, GetLanguageId(editor->GetFileName()));