Skip to content

Commit cd0c50c

Browse files
authored
Merge pull request #139 from hhefesto/fix-master-with-lsp
Fix master with lsp
2 parents e0c5b8b + c014107 commit cd0c50c

11 files changed

Lines changed: 905 additions & 68 deletions

app/LSP.hs

Lines changed: 514 additions & 0 deletions
Large diffs are not rendered by default.

emacs-telomare-mode/README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Telomare Mode for Emacs
2+
3+
LSP-enabled major mode for the Telomare programming language, with support for Doom Emacs, Spacemacs, and vanilla Emacs.
4+
5+
## Features
6+
7+
Based on the Telomare LSP server capabilities:
8+
- **Syntax highlighting** via semantic tokens (keywords, comments, strings, numbers, operators)
9+
- **Hover information** showing expression evaluation and parse errors
10+
- **Go to definition** and **Find references** (via LSP)
11+
- **Rename symbol** support
12+
- **Parse error reporting** displayed on hover
13+
- **Comment support** (`-- comments`)
14+
15+
## Installation
16+
17+
### Prerequisites
18+
19+
Ensure your Telomare LSP server is available at the configured path (default: `/home/hhefesto/src/telomare#lsp`).
20+
21+
### Modular Configuration (4 files)
22+
23+
Place all four files in a directory in your load-path. All variants require `telomare-mode-common.el`.
24+
25+
#### Doom Emacs
26+
27+
1. Place all files in `~/.doom.d/lisp/`
28+
2. Add to your `config.el`:
29+
```elisp
30+
(load! "lisp/telomare-mode-doom")
31+
```
32+
3. Run `doom sync`
33+
34+
#### Spacemacs
35+
36+
1. Place all files in `~/.spacemacs.d/lisp/`
37+
2. Add to `dotspacemacs/user-config`:
38+
```elisp
39+
(add-to-list 'load-path "~/.spacemacs.d/lisp/")
40+
(require 'telomare-mode-spacemacs)
41+
```
42+
3. Ensure the `lsp` layer is enabled in `dotspacemacs-configuration-layers`
43+
44+
#### Vanilla Emacs
45+
46+
1. Place all files in `~/.emacs.d/lisp/`
47+
2. Add to your `init.el`:
48+
```elisp
49+
(add-to-list 'load-path "~/.emacs.d/lisp/")
50+
(require 'telomare-mode-vanilla)
51+
```
52+
3. Install lsp-mode if not present:
53+
```elisp
54+
(package-install 'lsp-mode)
55+
```
56+
57+
## Configuration
58+
59+
### Customizing the LSP Command
60+
61+
```elisp
62+
;; Use a different nix path
63+
(setq telomare-lsp-command '("nix" "run" "/path/to/your/telomare#lsp" "--"))
64+
65+
;; Use a local binary
66+
(setq telomare-lsp-command '("/usr/local/bin/telomare-lsp"))
67+
```
68+
69+
## Key Bindings
70+
71+
### Doom Emacs
72+
- `SPC m g` - Go to definition TODO: improve
73+
- `SPC m G` - Find references
74+
- TODO: `SPC m h` - Describe at point (hover)
75+
- TODO: `SPC m r` - Rename symbol
76+
77+
### Spacemacs
78+
- `SPC m g` - Go to definition TODO: improve
79+
- `SPC m G` - Find references
80+
- TODO: `SPC m h` - Describe at point (hover)
81+
- TODO: `SPC m r` - Rename symbol
82+
83+
### Vanilla Emacs
84+
- `M-.` - Go to definition
85+
- `M-?` - Find references
86+
- TODO: `C-c h` - Describe at point (hover)
87+
- TODO: `C-c r` - Rename symbol
88+
89+
## Troubleshooting
90+
91+
1. **LSP not starting**: Test your LSP command in terminal:
92+
```bash
93+
nix run /home/hhefesto/src/telomare#lsp --
94+
```
95+
96+
2. **Check LSP status**: With a `.tel` file open, run:
97+
- `M-x lsp-describe-session`
98+
99+
3. **View LSP logs**: Check the `*lsp-log*` buffer for errors
100+
101+
## File Structure
102+
103+
- `telomare-mode-common.el` - Core mode definition and LSP client registration
104+
- `telomare-mode-doom.el` - Doom Emacs specific keybindings and setup
105+
- `telomare-mode-spacemacs.el` - Spacemacs specific keybindings and setup
106+
- `telomare-mode-vanilla.el` - Vanilla Emacs minimal configuration
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
;;; telomare-mode-common.el --- Common Telomare mode functionality -*- lexical-binding: t; -*-
2+
3+
;; Author: Your Name
4+
;; Version: 0.1.0
5+
;; Package-Requires: ((emacs "26.1"))
6+
;; Keywords: languages, telomare, lsp
7+
8+
;;; Commentary:
9+
10+
;; Common functionality for Telomare mode shared across all Emacs variants.
11+
;; The LSP server provides semantic tokens, hover, and text synchronization.
12+
13+
;;; Code:
14+
15+
(defgroup telomare nil
16+
"Support for the Telomare language."
17+
:group 'languages)
18+
19+
(defcustom telomare-lsp-command
20+
'("nix" "run" "/home/hhefesto/src/telomare#lsp" "--")
21+
"Command to start the Telomare LSP server."
22+
:type '(repeat string)
23+
:group 'telomare)
24+
25+
;; Define the major mode
26+
;;;###autoload
27+
(define-derived-mode telomare-mode prog-mode "Telomare"
28+
"Major mode for editing Telomare files."
29+
(setq-local comment-start "-- ")
30+
(setq-local comment-end "")
31+
(setq-local comment-start-skip "--+\\s-*"))
32+
33+
;; File association
34+
;;;###autoload
35+
(add-to-list 'auto-mode-alist '("\\.tel\\'" . telomare-mode))
36+
37+
;; Common LSP setup function
38+
(defun telomare-register-lsp-client ()
39+
"Register the Telomare LSP client."
40+
(when (fboundp 'lsp-register-client)
41+
(lsp-register-client
42+
(make-lsp-client
43+
:new-connection (lsp-stdio-connection
44+
(lambda () telomare-lsp-command))
45+
:activation-fn (lsp-activate-on "telomare")
46+
:major-modes '(telomare-mode)
47+
:server-id 'telomare-lsp))))
48+
49+
(provide 'telomare-mode-common)
50+
;;; telomare-mode-common.el ends here
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
;; ;; telomare lsp:
2+
3+
;; Define Telomare mode
4+
(define-derived-mode telomare-mode prog-mode "Telomare"
5+
"Major mode for editing Telomare files."
6+
(setq-local comment-start "-- ")
7+
(setq-local comment-end ""))
8+
9+
;; Associate .tel files with telomare-mode
10+
(add-to-list 'auto-mode-alist '("\\.tel\\'" . telomare-mode))
11+
12+
;; Configure LSP for Telomare using nix run
13+
(with-eval-after-load 'lsp-mode
14+
;; (add-to-list 'lsp-language-id-configuration '(telomare-mode . "telomare"))
15+
16+
;; Enable semantic tokens
17+
(setq lsp-semantic-tokens-enable t)
18+
19+
(lsp-register-client
20+
(make-lsp-client
21+
:new-connection (lsp-stdio-connection
22+
(lambda ()
23+
(list "nix" "run" "/home/hhefesto/src/telomare#lsp" "--")))
24+
:activation-fn (lsp-activate-on "telomare")
25+
:major-modes '(telomare-mode)
26+
:server-id 'telomare-lsp
27+
))
28+
)
29+
30+
;; Auto-start LSP in telomare-mode
31+
;; (add-hook 'telomare-mode-hook #'lsp-deferred) ;; lazier/non-blocking
32+
(add-hook 'telomare-mode-hook #'lsp)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
;;; telomare-mode-spacemacs.el --- Telomare major-mode + LSP for Spacemacs -*- lexical-binding: t; -*-
2+
3+
(defgroup telomare nil
4+
"Support for the Telomare language."
5+
:group 'languages)
6+
7+
(defcustom telomare-project-root
8+
(or (getenv "TELOMARE_ROOT")
9+
;; If this file lives inside the repo, try to auto-detect the flake root:
10+
(let* ((this (or load-file-name (buffer-file-name)))
11+
(dir (and this (file-name-directory this)))
12+
(root (and dir (locate-dominating-file dir "flake.nix"))))
13+
(when root (expand-file-name root))))
14+
"Path to the Telomare flake directory (the folder containing flake.nix).
15+
16+
Users should set this to something like \"~/src/telomare\".
17+
You can also set TELOMARE_ROOT in your environment."
18+
:type '(choice (const :tag "Auto-detect / unset" nil)
19+
(directory :tag "Telomare flake directory"))
20+
:group 'telomare)
21+
22+
(defcustom telomare-lsp-flake-attr "lsp"
23+
"Flake app/package attribute to run for the Telomare language server."
24+
:type 'string
25+
:group 'telomare)
26+
27+
(defun telomare--lsp-command ()
28+
"Return the command list used to start the Telomare LSP server."
29+
(unless (and telomare-project-root
30+
(file-exists-p (expand-file-name "flake.nix" telomare-project-root)))
31+
(user-error "telomare-project-root is not set (or has no flake.nix). Set it to your Telomare repo path"))
32+
(let* ((root (file-truename (expand-file-name telomare-project-root)))
33+
(flake (format "%s#%s" root telomare-lsp-flake-attr)))
34+
(list "nix" "run" flake "--")))
35+
36+
;; Define Telomare mode
37+
(define-derived-mode telomare-mode prog-mode "Telomare"
38+
"Major mode for editing Telomare files."
39+
(setq-local comment-start "-- ")
40+
(setq-local comment-end ""))
41+
42+
;; Associate .tel files with telomare-mode
43+
(add-to-list 'auto-mode-alist '("\\.tel\\'" . telomare-mode))
44+
45+
;; Configure LSP for Telomare
46+
(with-eval-after-load 'lsp-mode
47+
(setq lsp-semantic-tokens-enable t)
48+
(add-to-list 'lsp-language-id-configuration '(telomare-mode . "telomare"))
49+
(lsp-register-client
50+
(make-lsp-client
51+
:new-connection (lsp-stdio-connection #'telomare--lsp-command)
52+
:activation-fn (lsp-activate-on "telomare")
53+
:major-modes '(telomare-mode)
54+
:server-id 'telomare-lsp)))
55+
56+
;; Auto-start LSP in telomare-mode
57+
(add-hook 'telomare-mode-hook #'lsp)
58+
59+
(provide 'telomare-mode-spacemacs)
60+
;;; telomare-mode-spacemacs.el ends here
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
;;; telomare-mode-vanilla.el --- Telomare mode configuration for vanilla Emacs -*- lexical-binding: t; -*-
2+
3+
;; Author: Your Name
4+
;; Version: 0.1.0
5+
;; Package-Requires: ((emacs "26.1") (lsp-mode "8.0.0"))
6+
7+
;;; Commentary:
8+
9+
;; Vanilla Emacs specific configuration for Telomare mode.
10+
;; Add (require 'telomare-mode-vanilla) to your init.el
11+
12+
;;; Code:
13+
14+
;; Load common functionality
15+
(require 'telomare-mode-common)
16+
17+
;; Ensure lsp-mode is available
18+
(require 'lsp-mode)
19+
20+
;; Vanilla Emacs specific setup
21+
(defun telomare-vanilla-setup ()
22+
"Set up Telomare mode for vanilla Emacs."
23+
;; Register LSP client
24+
(telomare-register-lsp-client)
25+
26+
;; Add LSP hook
27+
(add-hook 'telomare-mode-hook #'lsp-deferred 'append)
28+
29+
;; Set up minimal keybindings
30+
(define-key telomare-mode-map (kbd "M-.") #'lsp-find-definition)
31+
(define-key telomare-mode-map (kbd "M-?") #'lsp-find-references)
32+
(define-key telomare-mode-map (kbd "C-c h") #'lsp-describe-thing-at-point)
33+
(define-key telomare-mode-map (kbd "C-c r") #'lsp-rename)
34+
(define-key telomare-mode-map (kbd "C-c a") #'lsp-execute-code-action))
35+
36+
;; Initialize
37+
(telomare-vanilla-setup)
38+
39+
(provide 'telomare-mode-vanilla)
40+
;;; telomare-mode-vanilla.el ends here

examples.tel

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
-- File for small illustrative telomare programs and for testing
22

33
-- Hello World example.
4-
main = \input -> ("Hello, World!", 0)
4+
aux = "Hello"
5+
-- main = \input -> (aux, 0)
6+
main = \input -> ("Hello", 0)
57

68
-- -- refinement fail
79
-- main : (\x -> if x then "fail" else 0) = 1
@@ -16,10 +18,13 @@ main = \input -> ("Hello, World!", 0)
1618
-- else abort "Not a MyInt"
1719
-- )
1820
-- in wrapper (# wrapper)
21+
1922
-- aux = \x -> if dEqual x 8 then "Success" else "Failure"
2023
-- main = \i -> (aux ((left MyInt) 8), 0)
2124

22-
-- Case example
25+
-- aux2 = [1,2,3]
26+
27+
-- something
2328
-- main =
2429
-- let toCase = (("a string", 99),(8,"pattern-match"))
2530
-- caseTest =

flake.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
type = "app";
6767
program = self.packages.${system}.telomare + "/bin/telomare-evaluare";
6868
};
69+
apps.lsp = {
70+
type = "app";
71+
program = "${self.packages.${system}.telomare}/bin/telomare-lsp";
72+
};
6973

7074
checks = self'.packages;
7175
};

0 commit comments

Comments
 (0)