Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development
Code completion using LSP and clangd
killerbot:
found it, thanks.
ollydbg:
--- Quote from: Pecan on December 28, 2022, 08:24:34 pm ---Could you give me some example code that is causing the problem.
Maybe I can be more precise in showing the declaration vs the definition.
--- End quote ---
I think every C++ member function will demonstrate this issue.
For example, I just searched a simple C++ tutorial here: C++ Class Member Functions
And the test code is below:
--- Code: ---#include <iostream>
using namespace std;
class Box {
public:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
// Member functions declaration
double getVolume(void);
void setLength( double len );
void setBreadth( double bre );
void setHeight( double hei );
};
// Member functions definitions
double Box::getVolume(void) {
return length * breadth * height;
}
void Box::setLength( double len ) {
length = len;
}
void Box::setBreadth( double bre ) {
breadth = bre;
}
void Box::setHeight( double hei ) {
height = hei;
}
// Main function for the program
int main() {
Box Box1; // Declare Box1 of type Box
Box Box2; // Declare Box2 of type Box
double volume = 0.0; // Store the volume of a box here
// box 1 specification
Box1.setLength(6.0);
Box1.setBreadth(7.0);
Box1.setHeight(5.0);
// box 2 specification
Box2.setLength(12.0);
Box2.setBreadth(13.0);
Box2.setHeight(10.0);
// volume of box 1
volume = Box1.getVolume();
cout << "Volume of Box1 : " << volume <<endl;
// volume of box 2
volume = Box2.getVolume();
cout << "Volume of Box2 : " << volume <<endl;
return 0;
}
--- End code ---
Find declaration of function "getVolume", will jump between from the function declaration in C++ class definition and function body "double Box::getVolume(void)".
BTW: sorry for the late reply, I just recovered from COVID-19 infection.
Pecan:
--- Quote from: ollydbg on January 08, 2023, 04:03:46 am ---
--- Quote from: Pecan on December 28, 2022, 08:24:34 pm ---Could you give me some example code that is causing the problem.
Maybe I can be more precise in showing the declaration vs the definition.
--- End quote ---
I think every C++ member function will demonstrate this issue.
For example, I just searched a simple C++ tutorial here: C++ Class Member Functions
And the test code is below:
--- Code: ---#include <iostream>
using namespace std;
class Box {
public:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
// Member functions declaration
double getVolume(void);
void setLength( double len );
void setBreadth( double bre );
void setHeight( double hei );
};
// Member functions definitions
double Box::getVolume(void) {
return length * breadth * height;
}
void Box::setLength( double len ) {
length = len;
}
void Box::setBreadth( double bre ) {
breadth = bre;
}
void Box::setHeight( double hei ) {
height = hei;
}
// Main function for the program
int main() {
Box Box1; // Declare Box1 of type Box
Box Box2; // Declare Box2 of type Box
double volume = 0.0; // Store the volume of a box here
// box 1 specification
Box1.setLength(6.0);
Box1.setBreadth(7.0);
Box1.setHeight(5.0);
// box 2 specification
Box2.setLength(12.0);
Box2.setBreadth(13.0);
Box2.setHeight(10.0);
// volume of box 1
volume = Box1.getVolume();
cout << "Volume of Box1 : " << volume <<endl;
// volume of box 2
volume = Box2.getVolume();
cout << "Volume of Box2 : " << volume <<endl;
return 0;
}
--- End code ---
Find declaration of function "getVolume", will jump between from the function declaration in C++ class definition and function body "double Box::getVolume(void)".
BTW: sorry for the late reply, I just recovered from COVID-19 infection.
--- End quote ---
Is this source all in one .cpp file or split between a .h and .cpp source file ?
Glad you made it through covid. I know how awful that suff is. I got it before there was any vaccine. It's dangerous.
ollydbg:
--- Quote from: Pecan on January 09, 2023, 06:22:50 pm ---Is this source all in one .cpp file or split between a .h and .cpp source file ?
--- End quote ---
If you put all the source code in a single .cpp file, find declaration will jump only in a single file between two lines. First from one line to another, and return back.
If you split them in a .h and .cpp file, you will jump between the two files.
--- Quote ---Glad you made it through covid. I know how awful that suff is. I got it before there was any vaccine. It's dangerous.
--- End quote ---
Thanks, I wish all our devs and C::B users good health, happy coding!
Pecan:
--- Quote from: ollydbg on December 28, 2022, 09:43:03 am ---Hi, I see one issue today.
In the latest clangd_client (0.61), I see that "find declaration" and "find implementation" context menu item just do the same thing.
Here, I can see when I click on either item, it just jump between the function declaration and implementation.
--- End quote ---
This "bounce" behavior is how clangd is currently working.
If the user asks for a declaration while positioned on it, clangd will respond with the implementation location and vise versa.
They seem to think that's how a "smart editor" should act.
i.e., "Do what I meant to do" behavior. Read my mind, not my mouse.
https://github.com/clangd/clangd/issues/713
I've spent 25 hours trying to get this to behave how the old CodeCompletion behaved.
Alas, I've failed, since it would require parsing the file text of the "GoTo/Find"response. That would get us back to the problem we're trying to get away from, namely parsing c++ code.
I'm leaving it as is until (maybe) clangd gives us an option to circumvent this behavior.
Suggestions welcomed.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version