Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development
Code completion using LSP and clangd
killerbot:
and what does it do with :
using TypeA = TypeB;
ollydbg:
--- Quote from: killerbot on March 23, 2022, 05:29:58 pm ---and what does it do with :
using TypeA = TypeB;
--- End quote ---
The same issue as the typedef.
Here is a simple test:
The cbp only contains main.cpp
--- Code: ---#include "TypeA.h"
int main()
{
TypeA a;
return 0;
}
--- End code ---
And here are the TypeA.h
--- Code: ---#include "TypeB.h"
// typedef TypeB TypeA;
using TypeA = TypeB;
--- End code ---
Here is TypeB.h
--- Code: ---class TypeB
{
public:
int abc;
};
--- End code ---
For testing, you can put the TypeA.h and TypeB.h in the same folder as main.cpp.
No, I can see that find declaration only goes from a file in cbp file to external file(a file not belong to cbp), such as main.cpp -> TypeA.h.
But find declaration will NOT go from an external file to an external file, so it failed from TypeA.h ->TypeB.h.
This is really an annoying issue. (BTW: our old code completion plugin works OK on this issue :) )
ollydbg:
--- Code: ---// ----------------------------------------------------------------------------
void CodeCompletion::OnGotoDeclaration(wxCommandEvent& event)
// ----------------------------------------------------------------------------
{
ProjectManager* pPrjMgr = Manager::Get()->GetProjectManager();
cbProject* pActiveProject = pPrjMgr->GetActiveProject();
if (not GetLSPclient(pActiveProject)) return;
EditorManager* pEdMgr = Manager::Get()->GetEditorManager();
cbEditor* pActiveEditor = pEdMgr->GetBuiltinActiveEditor();
if (!pActiveEditor)
return;
TRACE(_T("OnGotoDeclaration"));
const int pos = pActiveEditor->GetControl()->GetCurrentPos();
const int startPos = pActiveEditor->GetControl()->WordStartPosition(pos, true);
const int endPos = pActiveEditor->GetControl()->WordEndPosition(pos, true);
wxString targetText;
targetText << pActiveEditor->GetControl()->GetTextRange(startPos, endPos);
if (targetText.IsEmpty())
return;
// prepare a boolean filter for declaration/implementation
bool isDecl = event.GetId() == idGotoDeclaration || event.GetId() == idMenuGotoDeclaration;
bool isImpl = event.GetId() == idGotoImplementation || event.GetId() == idMenuGotoImplementation;
// ----------------------------------------------------------------------------
// LSP Goto Declaration/definition //(ph 2020/10/12)
// ----------------------------------------------------------------------------
bool usingLSP_client = true;
if (usingLSP_client)
{
// Assure editors file belongs to the active project (else it's not parsed yet).
ProjectFile* pProjectFile = pActiveEditor->GetProjectFile();
cbProject* pEdProject = pProjectFile ? pProjectFile->GetParentProject() : nullptr;
wxString filename = pActiveEditor->GetFilename();
if ( (not pEdProject)
//?or (not (pEdProject == pActiveProject)) //(ph 2022/02/15)
//?or (not pActiveProject->GetFileByFilename(filename,false)) //(ph 2022/02/15)
or (not GetLSPclient(pEdProject))
)
{
//? InfoWindow::Display("LSP " + wxString(__FUNCTION__), "Editor's file is not contained in the active project.", 6000); //(ph 2022/02/15)
wxString msg = _("The editor's file does not have an associated ");
if (not pEdProject)
msg << _("project.") << _("\nPerhaps add the file to a project ?");
else if (not GetLSPclient(pEdProject))
msg << "clangd_client." << _("\nPerhaps the project needs to be reparsed ?");
cbMessageBox(msg, "LSP " + wxString(__FUNCTION__));
return;
}
--- End code ---
If I looked at the comment "// Assure editors file belongs to the active project (else it's not parsed yet)."
I think it is not correct, I'm not sure clangd has some feature to query if a file is parsed or not, any one know the research direction? :) Because I can only find some information about clangd in this page: What is clangd?, I'm not sure where is the official document of clangd, maybe I need to read the document about LSP?
EDIT:
Maybe, the LSP document is here:
language-server-protocol/protocol-2-x.md at main microsoft/language-server-protocol
Pecan:
--- Quote from: ollydbg on March 25, 2022, 04:04:29 am ---
If I looked at the comment "// Assure editors file belongs to the active project (else it's not parsed yet)."
I think it is not correct, I'm not sure clangd has some feature to query if a file is parsed or not, any one know the research direction?-server-protocol[/url]
--- End quote ---
I apologize for not responding. But I'm in the middle of the US tax season. I'll respond as soon as I can get my head out of the tax instructions.
This is not a clangd problem.
It's a "this programmer failed to implement sending non-project files to clangd" problem.
ollydbg:
--- Quote from: Pecan on March 25, 2022, 05:44:33 am ---
--- Quote from: ollydbg on March 25, 2022, 04:04:29 am ---
If I looked at the comment "// Assure editors file belongs to the active project (else it's not parsed yet)."
I think it is not correct, I'm not sure clangd has some feature to query if a file is parsed or not, any one know the research direction?-server-protocol[/url]
--- End quote ---
I apologize for not responding. But I'm in the middle of the US tax season. I'll respond as soon as I can get my head out of the tax instructions.
This is not a clangd problem.
It's a "this programmer failed to implement sending non-project files to clangd" problem.
--- End quote ---
Hi, Pecan, thanks for the reply.
Maybe, we can have a mechanism that if a non-project file is opened in the editor, we can dynamically add(send) it to the clangd's database, and once the editor is closed, its content(the file) can be dynamically removed from the clangd's database.
This is only a guess.
Because, for my previous example, if I put the "TypeA.h", "TypeB.h" in the cbp file, then I see the find declaration works correctly in either header files. :)
EDIT:
This issue maybe is related to this github issue:
Support non-self-contained files Issue #45 clangd/clangd
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version