Bug 449966

Summary: [Feature Request] cargo clippy code analysis
Product: [Applications] kate Reporter: infrandomness
Component: applicationAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: wishlist CC: christoph, waqar.17a
Priority: NOR    
Version First Reported In: 21.12.2   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: code analysis tab

Description infrandomness 2022-02-10 19:34:55 UTC
Created attachment 146550 [details]
code analysis tab

It would be really cool to be able to use cargo clippy for code analysis in Kate when editing rust projects.
 

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: openSUSE TW
(available in About System)
KDE Plasma Version: 5.25.0
KDE Frameworks Version: 5.90.0
Qt Version: 5.12.2
Comment 1 Waqar Ahmed 2022-02-10 19:52:06 UTC
Please consider adding some more details about your request, for instance, what is a clippy? How does one use it? How can it integrate with Kate? Etc. It makes it easier to understand what is wanted and thus easier for someone who wants to implement this feature.
Comment 2 infrandomness 2022-02-10 20:13:26 UTC
Yep, sorry.

Clippy is a formatting tool for rust https://github.com/rust-lang/rust-clippy.
It gives "advanced" formatting advices to the user.
It can be used by installing it (cargo install cargo-clippy) and then running cargo clippy at the root of a rust crate.
This fits perfectly in the scope of "Code analysis" tab of Kate.
Comment 3 Christoph Cullmann 2022-02-10 20:58:34 UTC
Sounds like some good fit, yes.

Are you interested in contributing a patch for this?

This is handled in kate.git/addons/project/tools
Comment 4 infrandomness 2022-02-11 01:54:38 UTC
(In reply to Christoph Cullmann from comment #3)
> Sounds like some good fit, yes.
> 
> Are you interested in contributing a patch for this?
> 
> This is handled in kate.git/addons/project/tools

Sure ! I'd be glad to try and do this
Comment 5 infrandomness 2022-02-11 13:14:34 UTC
(In reply to Christoph Cullmann from comment #3)
> Sounds like some good fit, yes.
> 
> Are you interested in contributing a patch for this?
> 
> This is handled in kate.git/addons/project/tools

I am not seeing the changes I am making in the code being reflected in the binary or even in the compiler, I think I may be doing something wrong.
I am running the cmake "kate-bin" profile, is this normal?
Comment 6 Waqar Ahmed 2022-02-11 14:37:36 UTC
I assume you cloned the repo and did 

mkdir build
cd build
cmake .. 
make
./bin/kate # run

if so, the kate that gets run loads system plugins and not the ones you built yourself. To do the latter, run kate like:

QT_PLUGIN_PATHS=./bin ./bin/kate -n .

Also make sure, you build the whole project and not just the target "kate-bin".

Alternatively, you can use kdesrcbuild but that takes a lot of time.
Comment 7 Waqar Ahmed 2022-02-11 14:38:13 UTC
QT_PLUGIN_PATHS => QT_PLUGIN_PATH

typo^
Comment 8 infrandomness 2022-02-11 17:44:05 UTC
(In reply to Waqar Ahmed from comment #6)
> I assume you cloned the repo and did 
> 
> mkdir build
> cd build
> cmake .. 
> make
> ./bin/kate # run
> 
> if so, the kate that gets run loads system plugins and not the ones you
> built yourself. To do the latter, run kate like:
> 
> QT_PLUGIN_PATHS=./bin ./bin/kate -n .
> 
> Also make sure, you build the whole project and not just the target
> "kate-bin".
> 
> Alternatively, you can use kdesrcbuild but that takes a lot of time.

I did exactly this process : 
mkdir build
cd build
cmake .. 
make
QT_PLUGIN_PATH=./bin ./bin/kate
(while being in the build folder)
But the analysis tools don't seem to get compiled
Comment 9 infrandomness 2022-02-11 17:46:58 UTC
How do I make sure I am building those as well? I am very new to CMake
Comment 10 infrandomness 2022-02-11 17:48:07 UTC
Running make "katebuildplugin" seems to tell me there is nothing to be built...
Comment 11 Waqar Ahmed 2022-02-11 17:49:56 UTC
Maybe you forgot to add the new tool's implementation files to `addons/project/CMakeLists.txt`?

Check for other tools files that are in that file and just add yours below them:

    tools/kateprojectcodeanalysistoolclazycurrent.cpp // already there
    cargoclippytool.cpp // new file
Comment 12 infrandomness 2022-02-11 17:53:12 UTC
I have done this part 
```rs
Index: addons/project/CMakeLists.txt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/addons/project/CMakeLists.txt b/addons/project/CMakeLists.txt
--- a/addons/project/CMakeLists.txt	(revision bccf9a58ab1bb6f435eb942b46a2931dd9aedd0d)
+++ b/addons/project/CMakeLists.txt	(date 1644573992761)
@@ -80,6 +80,7 @@
     tools/kateprojectcodeanalysisselector.cpp
     tools/kateprojectcodeanalysistoolclazy.cpp
     tools/kateprojectcodeanalysistoolclazycurrent.cpp
+    tools/kateprojectcodeanalysistoolclippy.cpp
 
     git/gitdiff.cpp
     git/gitutils.cpp
```
Comment 13 Waqar Ahmed 2022-02-11 18:05:22 UTC
> Running make "katebuildplugin" seems to tell me there is nothing to be built...

That's not right. Either just run "make" or "make kateprojectplugin". Build plugin is different. You can find the plugin name usually by looking at the CMakeLists.txt file. There will be a ling

add_library(kateprojectplugin # plugin target name
...
)
Comment 14 Christoph Cullmann 2022-02-11 21:50:56 UTC
I would propose to just run always make.
If you have once compiled the stuff in kate, only the changed stuff will be recompiled anyways.
Did you have success in the mean time to get it to compile?
Comment 15 infrandomness 2022-02-12 20:06:13 UTC
(In reply to Christoph Cullmann from comment #14)
> I would propose to just run always make.
> If you have once compiled the stuff in kate, only the changed stuff will be
> recompiled anyways.
> Did you have success in the mean time to get it to compile?

No
Comment 16 infrandomness 2022-02-12 20:13:09 UTC
Seeing how make compiles different files in addon/, it seems to never go over addon/project entirely, maybe there's a specific option I need to feed to CMake for make to build the analysis tools?
Comment 17 Waqar Ahmed 2022-02-13 10:27:57 UTC
Ah, I guess you don't have the libraries installed and hence the project plugin never builds ;/ I guess we should have a warning in such cases at least so the user can know what happened.

You need at least these libraries;

    Qt5::Concurrent
    KF5::GuiAddons
    KF5::I18n
    KF5::NewStuff
    KF5::TextEditor

package names should be:

- libQt5Concurrent-devel
- libKF5GuiAddons5
- libKF5I18n5
...

Maybe there is a way to install the build dependencies for a package automatically in TW, not sure.
Comment 18 infrandomness 2022-02-14 09:54:48 UTC
Right.
I have this : 
```
 * KF5NewStuff (required version >= 5.83.0)
   Required to build the project addon
   Required to build the snippets addon
```
And I have the KF5NewStuff at version 5.90.0
Is my version too recent for Kate?
Comment 19 Waqar Ahmed 2022-02-14 10:09:46 UTC
No.

after building check if there is a `kateprojectplugin.so` file in the `build/bin/ktexteditor` directory. If it exists, that means project plugin got built successfully and then you can test it by running the command I gave you above.
Comment 20 infrandomness 2022-02-14 10:52:48 UTC
Well, for some reason, I have KF5NewStuff v5.90.0 on my machine, and cmake still isn't able to detect it.
Do I need some kind of *-devel package for this?
Comment 21 Waqar Ahmed 2022-02-14 11:04:58 UTC
yes, devel package
Comment 22 infrandomness 2022-02-14 11:51:43 UTC
(In reply to Waqar Ahmed from comment #21)
> yes, devel package

I've been trying to find a libKF5NewStuff5-devel package, or something rather similar to it in the oS TW repos, couldn't find anything.
Do you have any insight on what the package name could be?
Comment 23 Waqar Ahmed 2022-02-14 11:53:17 UTC
No, but I would suggest you to join the kde-devel chat on IRC / Matrix / Telegram and ask someone there.
Comment 24 Waqar Ahmed 2022-02-14 11:53:44 UTC
Also, pasting your full cmake output will be more helpful.
Comment 25 Waqar Ahmed 2023-01-11 18:10:50 UTC
Git commit db17711cf58079fb381c1f3a6673259ca588c564 by Waqar Ahmed.
Committed on 11/01/2023 at 17:13.
Pushed by waqar into branch 'master'.

Add Clippy tool

M  +1    -0    addons/project/CMakeLists.txt
M  +1    -0    addons/project/kateprojectinfoviewcodeanalysis.cpp
A  +98   -0    addons/project/tools/clippy.cpp     [License: LGPL(v2.0+)]
A  +41   -0    addons/project/tools/clippy.h     [License: LGPL(v2.0+)]
M  +3    -0    addons/project/tools/codeanalysisselector.cpp

https://invent.kde.org/utilities/kate/commit/db17711cf58079fb381c1f3a6673259ca588c564