Skip to content

Commit

Permalink
feat(emacs): add Java support
Browse files Browse the repository at this point in the history
  • Loading branch information
gekoke committed Feb 16, 2024
1 parent 0c1eccd commit 11c8bf9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions modules/nixos/programs/emacs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,25 @@ in
# Python
nodePackages.pyright
ruff-lsp
# Java
jdk21
jdt-language-server
];

elementary.home = {
programs.emacs = {
enable = true;
package = emacsPackage;
extraConfig = ''
(setq lsp-java-server-install-dir "${pkgs.jdt-language-server}/share/java/jdtls")
(setq lsp-java-server-config-dir (concat (file-name-as-directory (xdg-config-home)) "lsp-java/config_linux/"))
(add-to-list 'lsp-java-vmargs "-javaagent:${pkgs.elementary.lombok-jar}/share/java/lombok.jar")
'';
};
file = {
".emacs.d/init.el".source = ./init.el;
".emacs.d/early-init.el".text = earlyInitText;
".config/lsp-java/config_linux/config.ini".source = "${pkgs.jdt-language-server}/share/java/jdtls/config_linux/config.ini";
};
};

Expand Down
6 changes: 6 additions & 0 deletions modules/nixos/programs/emacs/init.el
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,12 @@
(bound-and-true-p lsp-mode))
(lsp-format-buffer)))))

(use-package lsp-java
:init
(add-hook 'java-ts-mode-hook . (lambda ()
(require 'lsp-java)
(lsp))))

(use-package markdown-mode
:custom
(markdown-fontify-code-blocks-natively t)
Expand Down
25 changes: 25 additions & 0 deletions packages/lombok-jar/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ lib, stdenv, fetchurl }:

stdenv.mkDerivation rec {
pname = "lombok-jar";
version = "1.18.30";

src = fetchurl {
url = "https://projectlombok.org/downloads/lombok-${version}.jar";
sha256 = "sha256-1+4SLu4erutFGCqJ/zb8LdCGhY0bL1S2Fcb+97odYBI=";
};

buildCommand = ''
mkdir -p $out/share/java
cp $src $out/share/java/lombok.jar
'';

meta = {
description = "A library that can write a lot of boilerplate for your Java project";
platforms = lib.platforms.all;
sourceProvenance = with lib.sourceTypes; [ binaryBytecode ];
license = lib.licenses.mit;
homepage = "https://projectlombok.org/";
maintainers = [ lib.maintainers.CrystalGamma ];
};
}

0 comments on commit 11c8bf9

Please sign in to comment.