yeet
This commit is contained in:
94
.config/emacs/modules/lang/scala/README.org
Normal file
94
.config/emacs/modules/lang/scala/README.org
Normal file
@@ -0,0 +1,94 @@
|
||||
#+TITLE: lang/scala
|
||||
#+DATE: October 14, 2020
|
||||
#+SINCE: v1.3
|
||||
#+STARTUP: inlineimages
|
||||
|
||||
* Table of Contents :TOC_3:noexport:
|
||||
- [[#description][Description]]
|
||||
- [[#module-flags][Module Flags]]
|
||||
- [[#lsp-integration][=+lsp= Integration]]
|
||||
- [[#prerequisites][Prerequisites]]
|
||||
- [[#coursier][Coursier]]
|
||||
- [[#metals][Metals]]
|
||||
- [[#features][Features]]
|
||||
- [[#notes][Notes]]
|
||||
|
||||
* Description
|
||||
This module adds [[https://www.scala-lang.org][scala]] and [[https://www.scala-sbt.org/][sbt]] support to Doom Emacs.
|
||||
|
||||
** Module Flags
|
||||
+ =+lsp= Enables integration for the metals LSP server.
|
||||
|
||||
|
||||
* =+lsp= Integration
|
||||
|
||||
** Prerequisites
|
||||
|
||||
*** Coursier
|
||||
Note: Coursier is only required to install Metals. If system is running arch
|
||||
linux this step can be safely skipped.
|
||||
|
||||
**** Ubuntu / Debian / Fedora
|
||||
#+BEGIN_SRC sh
|
||||
curl -fLo cs https://git.io/coursier-cli-linux &&
|
||||
chmod +x cs &&
|
||||
./cs
|
||||
#+END_SRC
|
||||
|
||||
**** MacOS
|
||||
#+BEGIN_SRC sh
|
||||
curl -fLo cs https://git.io/coursier-cli-macos &&
|
||||
chmod +x cs &&
|
||||
(xattr -d com.apple.quarantine cs || true) &&
|
||||
./cs
|
||||
#+END_SRC
|
||||
|
||||
**** Arch
|
||||
#+BEGIN_SRC sh
|
||||
yay -S coursier
|
||||
#+END_SRC
|
||||
|
||||
*** Metals
|
||||
|
||||
**** Ubuntu / Debian / Fedora / MacOS
|
||||
Note: Update following command to latest version of metals [[https://scalameta.org/metals/docs/editors/emacs.html][found here]].
|
||||
|
||||
#+begin_src sh
|
||||
coursier bootstrap \
|
||||
--java-opt -Xss4m \
|
||||
--java-opt -Xms100m \
|
||||
--java-opt -Dmetals.client=emacs \
|
||||
org.scalameta:metals_2.12:0.9.4 \
|
||||
-r bintray:scalacenter/releases \
|
||||
-r sonatype:snapshots \
|
||||
-o /usr/local/bin/metals-emacs -f
|
||||
#+end_src
|
||||
|
||||
**** Arch
|
||||
#+BEGIN_SRC sh
|
||||
yay -S metals
|
||||
#+END_SRC
|
||||
|
||||
** Features
|
||||
According to [[https://scalameta.org/metals/docs/editors/overview.html]] it adds
|
||||
|
||||
+ Goto Definition
|
||||
+ Completions
|
||||
+ Hover
|
||||
+ Paremeter Hints
|
||||
+ Find References
|
||||
+ Run/Debug
|
||||
+ Find Implementations
|
||||
+ Rename Symbol
|
||||
+ Code Actions
|
||||
+ Document Symbols
|
||||
+ Formatting
|
||||
+ Folding
|
||||
+ Organize Imports
|
||||
|
||||
** Notes
|
||||
|
||||
+ Projects are required to have scala version =2.11.12=, =2.12.8=, =2.13.0= or greater.
|
||||
+ Latest version of sbt is recommended.
|
||||
+ Running =M-x lsp-metals-doctor-run= helps diagnose problems.
|
||||
+ Full reference here: https://scalameta.org/metals/docs/editors/emacs.html
|
||||
54
.config/emacs/modules/lang/scala/autoload.el
Normal file
54
.config/emacs/modules/lang/scala/autoload.el
Normal file
@@ -0,0 +1,54 @@
|
||||
;;; lang/scala/autoload.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autoload
|
||||
(defun +scala-comment-indent-new-line-fn (&optional _)
|
||||
"Continue the commnt on the current line.
|
||||
|
||||
Meant to be used for `scala-mode's `comment-line-break-function'."
|
||||
(let* ((state (syntax-ppss))
|
||||
(comment-start-pos (nth 8 state)))
|
||||
(save-match-data
|
||||
(cond ((and (integerp (nth 4 state))
|
||||
;; Ensure that we're inside a scaladoc comment
|
||||
(string-match-p "^/\\*\\*?[^\\*]?"
|
||||
(buffer-substring-no-properties
|
||||
comment-start-pos
|
||||
(min (+ comment-start-pos 4)
|
||||
(point-max))))
|
||||
(progn
|
||||
(setq prev-line (buffer-substring-no-properties
|
||||
(line-beginning-position 0)
|
||||
(line-end-position 0)))
|
||||
(or (string-match "^\\s-*\\*" prev-line)
|
||||
(string-match "\\s-*/*" prev-line))))
|
||||
(newline nil t)
|
||||
(indent-according-to-mode)
|
||||
(insert (make-string (max 0 (- (1- (match-end 0))
|
||||
(match-beginning 0)))
|
||||
? )
|
||||
"*")
|
||||
(scala-indent:indent-on-scaladoc-asterisk))
|
||||
((nth 4 state) ; for line comments
|
||||
(call-interactively #'comment-indent-new-line))
|
||||
(t
|
||||
(newline nil t)
|
||||
(indent-according-to-mode))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +scala/open-repl ()
|
||||
"Open a scala repl. Uses `run-scala' if in a sbt project."
|
||||
(interactive)
|
||||
(if (and (require 'sbt-mode nil t)
|
||||
(sbt:find-root))
|
||||
(let ((buffer-name (sbt:buffer-name)))
|
||||
(when (and (get-buffer buffer-name) (not (comint-check-proc buffer-name)))
|
||||
(kill-buffer buffer-name))
|
||||
(run-scala)
|
||||
(get-buffer buffer-name))
|
||||
(let* ((buffer-name "*scala-repl")
|
||||
(buffer
|
||||
(if (comint-check-proc buffer-name)
|
||||
(get-buffer buffer-name)
|
||||
(make-comint-in-buffer "scala-repl" buffer-name "scala"))))
|
||||
(display-buffer buffer)
|
||||
buffer)))
|
||||
52
.config/emacs/modules/lang/scala/config.el
Normal file
52
.config/emacs/modules/lang/scala/config.el
Normal file
@@ -0,0 +1,52 @@
|
||||
;;; lang/scala/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(after! projectile
|
||||
(add-to-list 'projectile-project-root-files "build.sbt"))
|
||||
|
||||
|
||||
;;
|
||||
;;; Packages
|
||||
|
||||
(after! scala-mode
|
||||
(setq scala-indent:align-parameters t
|
||||
;; indent block comments to first asterix, not second
|
||||
scala-indent:use-javadoc-style t)
|
||||
|
||||
(setq-hook! 'scala-mode-hook
|
||||
comment-line-break-function #'+scala-comment-indent-new-line-fn)
|
||||
|
||||
(when (featurep! +lsp)
|
||||
(setq-hook! 'scala-mode-hook lsp-enable-indentation nil)
|
||||
(add-hook 'scala-mode-local-vars-hook #'lsp!))
|
||||
|
||||
(set-ligatures! 'scala-mode
|
||||
;; Functional
|
||||
:def "def"
|
||||
:composition "compose"
|
||||
;; HKT
|
||||
:lambda "Lambda"
|
||||
;; Types
|
||||
:null "none"
|
||||
:null "None"
|
||||
:true "true"
|
||||
:false "false"
|
||||
:int "Int"
|
||||
:str "String"
|
||||
:float "Float"
|
||||
:bool "Boolean"
|
||||
:list "List"
|
||||
;; Flow
|
||||
:for "for"
|
||||
:not "!"
|
||||
:and "&&"
|
||||
:or "||"
|
||||
:yield "yield"
|
||||
;; Other
|
||||
:union "union"
|
||||
:intersect "intersect"
|
||||
:diff "diff"))
|
||||
|
||||
|
||||
(use-package! sbt-mode
|
||||
:after scala-mode
|
||||
:config (set-repl-handler! 'scala-mode #'+scala/open-repl :persist t))
|
||||
9
.config/emacs/modules/lang/scala/doctor.el
Normal file
9
.config/emacs/modules/lang/scala/doctor.el
Normal file
@@ -0,0 +1,9 @@
|
||||
;;; lang/scala/doctor.el -*- lexical-binding: t; -*-
|
||||
|
||||
(assert! (or (not (featurep! +lsp))
|
||||
(featurep! :tools lsp))
|
||||
"This module requires (:tools lsp)")
|
||||
|
||||
(if (and (featurep! +lsp)
|
||||
(not (executable-find "metals-emacs")))
|
||||
(warn! "metals-emacs isn't installed"))
|
||||
8
.config/emacs/modules/lang/scala/packages.el
Normal file
8
.config/emacs/modules/lang/scala/packages.el
Normal file
@@ -0,0 +1,8 @@
|
||||
;; -*- no-byte-compile: t; -*-
|
||||
;;; lang/scala/packages.el
|
||||
|
||||
(package! sbt-mode :pin "e29464a82bf706ef921f4e0052ce04fc74c34c84")
|
||||
(package! scala-mode :pin "598cb680f321d9609295aa9b4679040cc703b602")
|
||||
|
||||
(when (featurep! +lsp)
|
||||
(package! lsp-metals :pin "695291761b2a3db734c3f53bb7fc4acfe0a5eb94"))
|
||||
Reference in New Issue
Block a user