-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[elisp] An initial version of a clef LSP client for Emacs
- Loading branch information
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(require 'package) | ||
;;; Add some Melpa archive | ||
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t) | ||
(package-initialize) | ||
|
||
(use-package lsp-mode) | ||
|
||
(load-file "clef.el") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
all: | ||
HOME=. emacs --no-splash example.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(use-package lsp-mode | ||
:ensure t | ||
:defer t | ||
:hook (lsp-mode . (lambda () | ||
(let ((lsp-keymap-prefix "C-c l")) | ||
(lsp-enable-which-key-integration)))) | ||
:config | ||
(define-key lsp-mode-map (kbd "C-c l") lsp-command-map)) | ||
|
||
(lsp-register-client | ||
(make-lsp-client | ||
:new-connection (lsp-stdio-connection '("clef" "--lsp" "--log=log" "--trace")) | ||
:major-modes '(c-mode) | ||
:priority 0 | ||
:activation-fn (lsp-activate-on "c") | ||
:server-id 'lsp-clef)) | ||
|
||
(setq lsp-client-packages (cons 'lsp-clef lsp-client-packages)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "clang_adapter.h" | ||
#include "common.h" | ||
#include "error.h" | ||
#include "filemanager.h" | ||
#include "log.h" | ||
#include "repl.h" | ||
#include "lsp.h" | ||
#include "options.h" | ||
|
||
|
||
protected int main_(int argc, char *argv[]) { | ||
log_set_level(LOG_FATAL); | ||
ResultCode rc = decode_options(argc, argv); | ||
if (rc != RC_OK) | ||
return EXIT_FAILURE; | ||
|
||
if (options.logfile_path != NULL) { | ||
FILE *log_file = fopen(options.logfile_path, "w"); | ||
log_add_fp(log_file, LOG_TRACE); | ||
} | ||
|
||
// TODO: Set CWD to argv[1] if available | ||
|
||
// TODO: create a compilation database object using clang_CompilationDatabase_fromDirectory() | ||
// TODO: use that to get compile flags and options for a specific translation unit | ||
FileTable fileTable = getTranslationUnitsFromCurrentDirectory(); | ||
|
||
CXIndex index = createIndex(0, 0); | ||
|
||
// TODO: create a table of filenames of all translation units, | ||
// all their dependent included files and their latest | ||
// modification time ... | ||
if (options.mode == CLI_MODE) | ||
cli_repl(fileTable, index); | ||
else { | ||
int pipe1[2], pipe2[2]; | ||
lsp_inject(options.lsp_server_path, pipe1, pipe2); | ||
lsp_repl(pipe1[1], pipe2[0], fileTable, index); | ||
} | ||
|
||
disposeIndex(index); | ||
freeFileTable(fileTable); | ||
|
||
return EXIT_SUCCESS; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
return main_(argc, argv); | ||
} |