Skip to content
Snippets Groups Projects
Commit 44a6b02c authored by Armin Mackensen's avatar Armin Mackensen
Browse files

add Support for Emacs LSP-mode + the py installer now create backups of files before they edit them

parent 070e6fa5
No related branches found
No related tags found
No related merge requests found
import os
import getpass
from os import path
from pathlib import Path
gitRepo = "https://git.se.informatik.uni-kiel.de/oceandsl/cp-dsl-replication"
nameOfRelease = "org.oceandsl.configuration.ide-1.3.0-SNAPSHOT-ls.jar"
#get the newest oceandsl lsp
os.system("sudo apt update && sudo apt install emacs")
Path(path.expanduser("~/temp")).mkdir(parents=True, exist_ok=True)
Path(path.expanduser("~/bin")).mkdir(parents=True, exist_ok=True)
os.system("wget -O " + "~/bin/" + nameOfRelease + " " + gitRepo + "/-/raw/master/" + nameOfRelease)
#get the newest oceandsl-mode for emacs
os.system("wget -O ~/bin/ " + gitRepo + "/-/raw/master/oceandsl-mode.el")
#get latest emacs init file
os.system("wget -O ~/temp/init.el " + gitRepo + "/-/raw/master/init.el")
initfileConf = False
#check if the user already has an init emacs file
if(os.path.exists(path.expanduser("~/.emacs.d/init.el"))):
initfileConf = True
os.system("cp ~/.emacs.d/init.el ~/.emacs.d/init.el.backup")
oldData = Path(path.expanduser("~/.emacs.d/init.el")).read_text()
newData = Path(path.expanduser("~/temp/init.el")).read_text()
if(not(oldData == newData or oldData in newData)):
oldData = Path(path.expanduser("~/.emacs.d/init.el")).write_text(oldData + newData)
#check if user has an .emacs init file
if(os.path.exists(path.expanduser("~/.emacs"))):
initfileConf = True
os.system("cp ~/.emacs ~/.emacs.backup")
oldData = Path(path.expanduser("~/.emacs")).read_text()
newData = Path(path.expanduser("~/temp/init.el")).read_text()
if(not(oldData == newData or oldData in newData)):
oldData = Path(path.expanduser("~/.emacs")).write_text(oldData + newData)
if(not initfileConf):
Path(path.expanduser("~/.emacs.d")).mkdir(parents=True, exist_ok=True)
os.system("mv ~/temp/init.el ~/.emacs.d/init.el")
os.system("emacs -nw")
os.system("rm ~/temp -r")
......@@ -27,6 +27,7 @@ Current technical limitations are listed in: `Limitations.md`
- Setup of the Editors
- Eclipse Setup
- Vim Setup
- Emacs Setup
- Jupyter Setup
- Utilizing the CP-DSL
- Using Eclipse
......@@ -51,7 +52,7 @@ Before you can install the CP-DSL in Eclipse you need to install Eclipse.
- Click on the Download button for the current version. This should start the
download and show the donate page, which can be ignored.
- Wait until the download is complete.
- Depending on your platform you may have zip, dmg or tar.gz archive.
- Depending on your platform you may have zip, exe, dmg or tar.gz archive.
- Unpack the archive and run the installer within the archive. On Linux this
can be done with:
- `tar -xvzpf eclipse-inst-jre-linux64.tar.gz` (unpack archive)
......@@ -84,15 +85,16 @@ Before you can install the CP-DSL in Eclipse you need to install Eclipse.
the entry `Configuration DSL`. Check the checkbox in front and click the
*Next >* button. `Configuration DSL` comprises of three features for
`Configuration`, `Declaration` and `Templates`.
- On the next page of the installation dialog these three features are shown.
- On the next page of the installation dialog these three features are shown. Plus some not any more required preinstalled packages.
- Click on *Finish* to download them.
- Now a *Security Warning* pops up indicating that our packages are not signed.
Unfortunately, this is still true, as the signing process is not trivial,
but will be fixed in future releases.
- To proceed with clicking on *Install Anyway*.
- To proceed, check the box next to the source and click on *trust selected*.
- Eclipse will install the extension and ask to restart.
- Click on *Restart Now*. This ensures that the features are installed
correctly.
- Eclipse will try to install the uninstalled not any more needed packages again, just ignore these.
- Now you are setup.
......@@ -109,6 +111,9 @@ operating system may differ.
- Install Java preferably Java 11.
### Installation
We provide an Python-Script for an easy installation. Just download the `VimSetupScript.py` and run it with `python3 VimSetupScript`.
Alternative manual installation:
- Install vim, e.g., with `sudo apt install vim`
- Copy `org.oceandsl.configuration.ide-1.0.0-SNAPSHOT-ls.jar` to a tooling
......@@ -130,14 +135,60 @@ operating system may differ.
In case the status is offline or exited, some error might have occurred.
One option is that the wrong java version is used. You can check this on
command line with `java -version`.
command line with `java -version`. For a more detailed analysis of the error you can check the VimLSP-logs in `~/vim-lsp.log`
In case the status is online, you are ready to go. Context help is available
In case the status is running, you are ready to go. Context help is available
with CTRL-Space, similarly to Eclipse.
**Notes:**
- Vim only provides editing capabilities. Compilation must be performed
by a command-line compiler.
## Emacs Setup
For the Emacs setup, we use the lsp-mode package and Java.
As in the Vim Installation, we provide Debian/Ubuntu compatible installation
commands in our documentation. The correct command for your distribution or
operating system may differ.
### Perquisites
- Install the Emacs lsp-mode from `https://emacs-lsp.github.io/lsp-mode/`
- Install Java preferably Java 11.
### Installation
We provide an Python-Script for an easy installation. Just download the `EmacsSetupScript.py` and run it with `python3 EmacsSetupScript`.
Alternative manual installation:
- Install `Emacs` with e.g. `sudo apt update && sudo apt install emacs`
- Run `Emacs` for the first time, so that it can create some standart folder, etc.
- To run `Emacs` within the console, type `emacs -nw` "nw" for "no-window"
- Download the latest version of the OceanDSL Language Server and put it in a folder (ex. `~/bin/`)
- Download the latest oceandsl-mode.el file and place it in i.e. the same folder (`~/bin/`)
edit the path to the jar file, so that it is correct
(make sure to use absolute path ex. `/home/user/bin/example.jar`)
- Merge or use the `init.el` as initial-instruction for `Emacs`
usally it is located at (`~/.emacs.d/init.el` or `~/.emacs`) if it is not there, than just create one.
Make sure, that the path in the init.el is the path to the folder where "oceandsl-mode.el" is located (ex. `~/bin/`)
- Open Emacs
The rest of the instructions use `M-x` as instruction for:
Press `ESC` and then `x` (`M-x`)
- install package lsp: `M-x` type `package-install` ENTER `lsp-mode` ENTER
if `Emacs` shows you ("could not found lsp-mode.[vers-number].tar") type: `M-x` `package-refresh-contents` ENTER
After Installation close `Emacs`
-Usage:
open an OceanDSL file
Just start the lsp-mode with `M-x` `lsp`
The LS should be started and you are good to go.
**Notes:**
- Should lsp-mode show you a bunch of warnings, type: `M-x` `load-library` ENTER `oceandsl-mode` ENTER (you can use tabulator for autocompletion).
If you cannot use auto-completion you configured the path to `oceandsl-mode.el` in `init.el` wrong.
- As in the Vim installation mentioned: Compilation must be performed by a command-line compiler.
## Jupyter Setup
......
......@@ -8,7 +8,7 @@ nameOfRelease = "org.oceandsl.configuration.ide-1.3.0-SNAPSHOT-ls.jar"
pathToJar = "/home/" + getpass.getuser() + "/bin/" + nameOfRelease
os.system("sudo apt install vim")
os.system("sudo apt update && sudo apt install vim")
Path(path.expanduser("~/temp")).mkdir(parents=True, exist_ok=True)
#print(path.expanduser("~/bin"))
Path(path.expanduser("~/bin")).mkdir(parents=True, exist_ok=True)
......@@ -21,7 +21,8 @@ os.system("wget -O ~/temp/example.vimrc " + gitRepo + "/-/raw/master/example.vim
if(os.path.exists(path.expanduser("~/.vimrc"))):
newData = Path(path.expanduser("~/temp/example.vimrc")).read_text().replace(nameOfRelease, pathToJar)
oldData = Path(path.expanduser("~/.vimrc")).read_text()
if(newData not in oldData):
os.system("cp ~/.vimrc ~/.vimrc.backup")
if(not(newData == oldData or newData in oldData)):
os.system("sudo chown " + getpass.getuser() + " ~/.vimrc")
Path(path.expanduser("~/.vimrc")).write_text(oldData + newData)
else:
......@@ -43,7 +44,8 @@ os.system("wget -O ~/temp/filetype.vim " + gitRepo + "/-/raw/master/filetype.vim
if(os.path.exists(path.expanduser("~/.vim/filetype.vim"))):
newData = Path(path.expanduser("~/temp/filetype.vim")).read_text()
oldData = Path(path.expanduser("~/.vim/filetype.vim")).read_text()
if(newData not in oldData):
os.system("cp ~/.vim/filetype.vim ~/.vim/filetype.vim.backup")
if(not(newData == oldData or newData in oldData)):
Path(path.expanduser("~/.vim/filetype.vim")).write_text(oldData + newData)
else:
os.system("mv ~/temp/filetype.vim ~/.vim/filetype.vim")
......
init.el 0 → 100644
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(package-initialize)
(unless package-archive-contents
(package-refresh-contents))
(unless (package-installed-p 'lsp-mode))
(package-install 'lsp-mode)
(add-to-list 'auto-mode-alist '("\\.oconf\\'" . oceandsl-mode))
;;add your folder to "oceandsl-mode.el" here as: "~/example/folder" for "~/bin"
(add-to-list 'load-path "~/bin")
(load-library "oceandsl-mode")
(add-to-list 'auto-mode-alist '("\\.oconf\\'" . oceandsl-mode))
(with-eval-after-load 'lsp-mode
(add-to-list 'lsp-language-id-configuration
'(oceandsl-mode . "oceandsl"))
(lsp-register-client
(make-lsp-client :major-modes '(oceandsl-mode)
:server-id 'oceandsl-ls
:activation-fn (lsp-activate-on "oceandsl")
:new-connection (lsp-stdio-connection (list "java" "-jar" oceandsl-ls-jar)))))
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(package-selected-packages '(lsp-mode)))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
;;; oceandsl-mode.el
;; Package-Requires: ((lsp-mode "6.0"))
;;; Commentary:
;; The main purpose of this mode is to demonstrate how to connect a language
;; server generated by Xtext (http://www.eclipse.org/Xtext/) to Emacs'
;; lsp-mode (https://github.com/emacs-lsp/lsp-mode).
(defconst oceandsl-keywords
(regexp-opt
'("configuration" "parameters" "module" "features"))
"List of keywords of the oconf language.")
(defconst oceandsl-types
(regexp-opt '("data" "source" "general"))
"List of standard types of the oconf language.")
(defvar oceandsl-font-lock-keywords
(list
(cons oceandsl-keywords 'font-lock-keyword-face)
(cons oceandsl-types 'font-lock-type-face)))
(defvar oceandsl-ls-jar
;; Should be something like "/home/user/bin/org.oceandsl.configuration.ide-1.3.0-SNAPSHOT-ls.jar"
(expand-file-name "/home/kali/bin/org.oceandsl.configuration.ide-1.3.0-SNAPSHOT-ls.jar"
(when load-file-name (file-name-directory load-file-name))))
;;;###autoload
(define-derived-mode oceandsl-mode prog-mode "oceandsl"
"Major mode for editing OceanDSL files.
The hook `prog-mode-hook' is run during initialization, then
`oceandsl-mode-hook'.
The following keys are set:
\\{oceandsl-mode-map}"
(setq font-lock-defaults '(oceandsl-font-lock-keywords))
(setq-local comment-use-syntax t)
(setq-local comment-start "//")
(setq-local comment-end "")
(setq-local comment-start-skip "//+\\s-*"))
;; `oceandsl-mode-syntax-table' is created by the `define-derived-mode' form
;; above, so here we can modify it to teach it about comments.
(modify-syntax-entry ?/ ". 124" oceandsl-mode-syntax-table)
(modify-syntax-entry ?* ". 23b" oceandsl-mode-syntax-table)
(modify-syntax-entry ?\n ">" oceandsl-mode-syntax-table)
(modify-syntax-entry ?\^m ">" oceandsl-mode-syntax-table)
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.oconf\\'" . oceandsl-mode))
;;;###autoload
(when (featurep 'lsp-mode)
;; https://emacs-lsp.github.io/lsp-mode/page/adding-new-language/
(add-to-list 'lsp-language-id-configuration
'(oceandsl-mode . "oceandsl"))
(lsp-register-client
(make-lsp-client :major-modes '(oceandsl-mode)
:server-id 'oceandsl-ls
:new-connection (lsp-stdio-connection (list "java" "-jar" oceandsl-ls-jar)))))
;;;###autoload
;;(when (featurep 'eglot)
;; https://github.com/joaotavora/eglot#connecting-to-a-server
;; (add-to-list 'eglot-server-programs `(oceandsl-mode . ("java" "-jar" ,oceandsl-ls-jar))))
(provide 'oceandsl-mode)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment