Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gjvanderheiden/nvim
My nvim config
https://github.com/gjvanderheiden/nvim
Last synced: about 1 month ago
JSON representation
My nvim config
- Host: GitHub
- URL: https://github.com/gjvanderheiden/nvim
- Owner: gjvanderheiden
- Created: 2024-01-09T19:08:02.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-07-16T11:46:42.000Z (5 months ago)
- Last Synced: 2024-07-16T14:31:16.991Z (5 months ago)
- Language: Lua
- Size: 66.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Intention of this repo:
This is just my config I use, so I use this as version control. The setup I'm using is for basic system maintanace / primary text editor as wel as a PDE / IDE. I now use it for Java and lua. So this might be another example how to setup jdtls-nvim. Looking for a one stop clicky click solution? This is not it. Want to know and control how your nvim works? You might pick something up here, that would be nice. In my scripts I don't check for excistance of installations, nor make it configurable for many users, by design. The advantage is that is keeps the lua scripts shorter. Distos like lazy have to write a lot of checking and glue code, because their goal is to hide this configuration stuff from the user as much as possible.
Maybe I'll do a seperate thing for just Java setup. Lua was pretty straight forward compared to Java with nvim-jdtls. For now I reference to the Java config parts in this readme. But it does some great stuff. I also want to add Python, C++, CMake, Swift and whatever I like to try out.
I wanted to learn vim motions and the basics, because I really started to dislike I could just do some basic editing and
felt like a real PHEW moment when I succesfully edited and saved a file, especially on the server. I then start to like the way
the vim motions work and thought, what if I set my CLion, IntelliJ and PyCharm to the vim editor. Now I have a editor with keybindings wich are the same over multiple platforms AND I can move fast, without touching the mouse. This just grew out of hand... I started using nvim more and more, to the point I really want to use it as my primary IDE.I don't care for spring, you won't find that here.
It is not ment as a config as is for everybody, but maybe this can serve as a sort of gist. Yank, Paste and Change Word all you like.
## Why not use a distro
You certainly could. E.g. LazyVim has a correct setup for Java. I use distros to pick and choose what I like. A distro is not my personal preference, because it takes effort to disable or change stuff too. And I like to know how it all works, so I know my system. Though I've worked many years with Eclipse and then IntelliJ with no issues. The latter just works. But now I've used neovim, I don't want to go back. I'm in the process of choosing keybindings while getting stuff to work. I really like you can do stuff like r r for [r]efactor->[r]ename. Together with [wich-key](https://github.com/folke/which-key.nvim) that is just simple, efficient and fun to work with.# Setup
I do not use Mason, as I like to use system package managers on my favourate OS-es, being MacOs (with homebrew) and Arch Linux (pacman). Mason is also a good option, but you'll have to adjust the paths I use in the scripts. Many plugins and distro's use Mason, because you can control de installation directories on the system. Just choose for yourself what you prefer. The description and scripts don't use Mason.## Needed packages
lsp-language-server
stylua
jdtls (AUR on Arch)# Java config in nvim
It took me a while to find out how this works out. First I tried Java support using lazynvim, which worked to some extend. Then I found a repo which says Java plug and play, which is just a grabbag of plugins with some glue code.
This is just a summary of what I've found
The is a lot to take in when you starting out with language support in nvim. In nvim has adopted the LSP, short for Language Server Protocol. Which is a protocol that blablabla see the internet. Then there are the following components:
- Eclipse jdtls, the language server itself
- nvim-jdtls, wrapper to attach Eclipse jdtls
- nvim-lspconfig, pops up when googling around on this topic, but do no use for jdtls!# jdtls config
## Do not use nvim-lspconfig for Java / jdtls
It is possible to use nvim-lspconfig to connect start jdtls, but this doesn't make full use of [nvim-jdtls](https://github.com/mfussenegger/nvim-jdtls). Mainly, it doens't jump to source code of external dependencies. It is in the readme of nvim-jdtls, but to me is was not that ovbious. Instead, ONLY configure nvim-jdtls to attach on Java files in nvim.## How to hook up nvim-jdtls
### Install Eclipse jdtls
You van use mason to do this, I use my OS for this. Especially on Arch linux, it's a rolling release distro. On MacOs you have [home brew](https://brew.sh). Both are so quick with updates, amazing work. On homebrew and pacman the package is called jdtls. On Arch it is a AUR package. For Homebrew that's just:
```
brew install jdtls
```If you're using yay on Arch Linux
```
yay -S jdtls
```### Add jdtls as a plugin
I use [lazyvim](https://github.com/folke/lazy.nvim) as package manager for nvim. It allows to make nice separate lua files for installing. But whatever. Just add it. [My version is here](https://github.com/gjvanderheiden/nvim/blob/main/lua/plugins/jdtls.lua)
```
return {
"mfussenegger/nvim-jdtls",
}
```### Attatch on opening a java file JavaType
This took some digging. The readme on nvim-jdtls tells you to use ftplugin. Though this might work somehow, I used an autocommand, that nicked that nice idea from [here](https://github.com/Alexis12119/nvim-config). If you don't know what an autocommand is, it's worth to have a look. Basically it's events with listeners. The autocommand listen to opening a buffer wioth a specific file type, Java in this case, and than we call jdtls.start_or_attach() and off we go.Also we add some Java specific keybindings on the attach, so we have the key bindings when nvim it actually using the Java language server.
[I do that in this scipt](https://github.com/gjvanderheiden/nvim/blob/main/lua/config/autocommands/jdtls.lua). The scripts also does something with bundles, that is for the next section DAP & Test.I do not use use the java command directly as on the Readme page of nvim-jdtls, but I use the jdtls executable which does everything I need.
The general keybindings are in a [seperate script](https://github.com/gjvanderheiden/nvim/blob/main/lua/config/autocommands/lsp-keymaps.lua). This autocommand listens to LspAttatch.
Now If you open a Java file, jdtls should run. You can verfiy with
```
:LspInfo
```
in nvim with a Java file opened.#### DAP (debugging in nvim) & Test
To be able to run tests within NeoVim, we need to add some more stuff. Just like the LSP config, the plugin nvim-jdtls does not make use of a configuring plugin like nvim-dapconfig and you do not need to define dap.adapters.java, as nvim-jdtls does that for you. You do need to add bundles to the config of jdtls via the nvim-jdtls plugin. It expects a lua table with full path .jar files. I've installed those in /opt/jdtls-bundles on my machine. In that directory I have java-debug and java-test directory, which contains the jars. The jars are extraced from the vscode plugins, because somehow mickeysoft thinks it is a good idea to put ever changing directory names in the plugin source. Now idea. So download the vs-code plugins, extract the jars, put this extention/server contents in /opt/jdtls-bundles/java-debug and /opt/jdtls-bundles/java-test directory. Then add them to the options.
This is done in the function get_bundles() which is called in the options table. [seperate script](https://github.com/gjvanderheiden/nvim/blob/main/lua/config/autocommands/jdtls.lua)In order to run a class with a Java main method, jdtls needs a call:
```
require('jdtls.dap').setup_dap_main_class_configs()
```This function only works when the lsp is running. In order to do that I added an [autocommand on LspAttatch](https://github.com/gjvanderheiden/nvim/blob/main/lua/config/autocommands/lsp-jdtls-dap.lua), which calls this function. Not really sure that's correct, but it seems to work.
## Missing functionality
There is a lot nvim with a bunch of plugins can do. But I'm missing the following:
- Browse project package. (not dirs, packages) Would like that with NavBuddy
- Run all tests, with a summary green of it it must, red
- Build
- maven editing support, dependency completion I miss the most
## Missing functionality, just not added yet
- Maybe attach jdtls on the start of a project / workspace or something. Now jdtls starts when any of the Java files are opened.
- Git with diff# Java LSPs
https://github.com/georgewfraser/java-language-server
https://github.com/eclipse-jdtls/eclipse.jdt.ls# Config and howto used
https://github.com/Alexis12119/nvim-config