Skip to content

Commit

Permalink
[elisp] An initial version of a clef LSP client for Emacs
Browse files Browse the repository at this point in the history
  • Loading branch information
thoni56 committed Mar 6, 2023
1 parent fda2c8a commit 81e9bad
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/emacs_plugin/.emacs.d/init.el
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")
2 changes: 2 additions & 0 deletions tests/emacs_plugin/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
HOME=. emacs --no-splash example.c
18 changes: 18 additions & 0 deletions tests/emacs_plugin/clef.el
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))
53 changes: 53 additions & 0 deletions tests/emacs_plugin/example.c
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);
}

0 comments on commit 81e9bad

Please sign in to comment.