Skip to content

Commit

Permalink
WIP LSP client
Browse files Browse the repository at this point in the history
This contains the start of an LSP client.
Nothing (except starting the LSP server) works
at the moment and the feature is disabled by default.
  • Loading branch information
abbec committed Sep 12, 2024
1 parent 4ab7e45 commit 405da5f
Show file tree
Hide file tree
Showing 66 changed files with 1,718 additions and 575 deletions.
28 changes: 21 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,35 @@ build:

.include "config.mk"
SYNTAX_ENABLE ?= true
LSP_ENABLE ?= true

HEADERS = src/dged/settings.h src/dged/minibuffer.h src/dged/keyboard.h src/dged/binding.h \
src/dged/buffers.h src/dged/text.h src/dged/display.h src/dged/hashmap.h src/dged/path.h \
src/dged/buffer.h src/dged/btree.h src/dged/command.h src/dged/allocator.h src/dged/reactor.h \
src/dged/vec.h src/dged/window.h src/dged/hash.h src/dged/undo.h src/dged/lang.h \
src/dged/settings-parse.h src/dged/utf8.h src/main/cmds.h src/main/bindings.h \
src/main/search-replace.h src/dged/location.h src/dged/buffer_view.h src/main/completion.h \
src/dged/timers.h src/dged/s8.h src/main/version.h src/config.h
src/dged/timers.h src/dged/s8.h src/main/version.h src/config.h src/dged/process.h

SOURCES = src/dged/binding.c src/dged/buffer.c src/dged/command.c src/dged/display.c \
src/dged/keyboard.c src/dged/minibuffer.c src/dged/text.c \
src/dged/utf8.c src/dged/buffers.c src/dged/window.c src/dged/allocator.c src/dged/undo.c \
src/dged/settings.c src/dged/lang.c src/dged/settings-parse.c src/dged/location.c \
src/dged/buffer_view.c src/dged/timers.c src/dged/s8.c
src/dged/buffer_view.c src/dged/timers.c src/dged/s8.c src/dged/path.c src/dged/hash.c

MAIN_SOURCES = src/main/main.c src/main/cmds.c src/main/bindings.c src/main/search-replace.c src/main/completion.c

# HACK: added to MAIN_SOURCES to not be picked up in tests
# since they have their own implementation
.if "$(HAS_EPOLL)" == true
MAIN_SOURCES += src/dged/reactor-epoll.c
.elif "$(HAS_KQUEUE)" == true
MAIN_SOURCES += src/dged/reactor-kqueue.c
.endif

.if "$(PROCESS_MODEL)" == posix
SOURCES += src/dged/process-posix.c
.endif

TEST_SOURCES = test/assert.c test/buffer.c test/text.c test/utf8.c test/main.c \
test/command.c test/keyboard.c test/fake-reactor.c test/allocator.c \
Expand All @@ -49,9 +55,9 @@ datadir = share/dged
.SUFFIXES:
.SUFFIXES: .c .o .d

CFLAGS += -Werror -g -O2 -std=c99 \
-I $(.CURDIR)/src \
-I $(.CURDIR)/src/main \
CFLAGS += -Werror -Wall -Wextra -g -O2 -std=c99\
-I $(.CURDIR)/src\
-I $(.CURDIR)/src/main\
-DDATADIR="$(prefix)/$(datadir)"

ASAN ?= false
Expand All @@ -66,12 +72,20 @@ ASAN ?= false
SOURCES += src/dged/syntax.c

treesitterflags != pkg-config tree-sitter --cflags
CFLAGS += ${treesitterflags} -DSYNTAX_ENABLE
CFLAGS += ${treesitterflags}

treesitterld != pkg-config tree-sitter --libs
LDFLAGS += ${treesitterld}
.endif

.if $(LSP_ENABLE) == true
HEADERS += src/dged/lsp.h src/main/lsp.h src/dged/json.h
SOURCES += src/dged/lsp.c src/dged/json.c
MAIN_SOURCES += src/main/lsp.c
TEST_SOURCES += test/json.c
CFLAGS += -DLSP_ENABLED
.endif

UNAME_S != uname -s | tr '[:upper:]' '[:lower:]'
.if exists(${.CURDIR}/${UNAME_S}.mk)
. include "$(.CURDIR)/$(UNAME_S).mk"
Expand Down Expand Up @@ -138,7 +152,7 @@ run: dged
./dged

debug: dged
gdb ./dged
gdb -ex "cd $(.CURDIR)" ./dged

debug-tests: run-tests
gdb ./run-tests
Expand Down
47 changes: 40 additions & 7 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
_usage="./configure -- configure the DGED build.
Options:
--[enable|disable]-syntax Enable or disable syntax highlighting support.
--enable-asan Build DGED with address sanitizer enabled.
--prefix=<PREFIX> Set the build prefix path to <PREFIX>, default: /usr/local.
--[enable|disable]-syntax Enable or disable syntax highlighting support. Default: enabled.
--[enable|disable]-lsp Enable or disable Language Server Protocol support. Default: disabled (experimental).
--enable-asan Build DGED with address sanitizer enabled. Default: disabled.
--prefix=<PREFIX> Set the build prefix path to <PREFIX>. Default: /usr/local.
-h/--help Show this help text.
"

enable_syntax=1
enable_lsp=0
enable_asan=0
prefix=
while [ "$#" -gt 0 ]; do
Expand All @@ -24,6 +26,16 @@ while [ "$#" -gt 0 ]; do
shift 1
;;

--enable-lsp)
enable_lsp=1
shift 1
;;

--disable-lsp)
enable_lsp=0
shift 1
;;

--enable-asan)
enable_asan=1
shift 1
Expand Down Expand Up @@ -75,21 +87,42 @@ else
echo "none."
fi

echo -n "detecting process model..."
if ./scripts/has_header "unistd.h"; then
echo "posix."
echo "#define PROCESS_MODEL posix" >> src/config.h
echo "PROCESS_MODEL ?= posix" >> config.mk
else
echo "unknown."
fi

if [ "$enable_syntax" -ne 0 ]; then
echo "enabling syntax highlighting"
echo "enabling syntax highlighting."
echo "SYNTAX_ENABLE = true" >> config.mk
echo "#define SYNTAX_ENABLE 1" >> src/config.h
else
echo "disabling syntax highlighting"
echo "disabling syntax highlighting."
echo "SYNTAX_ENABLE = false" >> config.mk
echo "#undef SYNTAX_ENABLE" >> src/config.h
fi

if [ "$enable_lsp" -ne 0 ]; then
echo "enabling language server support."
echo "LSP_ENABLE = true" >> config.mk
echo "#define LSP_ENABLE 1" >> src/config.h
else
echo "disabling language server support."
echo "LSP_ENABLE = false" >> config.mk
echo "#undef LSP_ENABLE" >> src/config.h
fi

if [ "$enable_asan" -ne 0 ]; then
echo "enabling address sanitizer"
echo "enabling address sanitizer."
echo "ASAN = true" >> config.mk
fi

if [ -n "$prefix" ]; then
echo "setting prefix to \"$prefix\""
echo "setting prefix to \"$prefix\"."
echo "prefix = $prefix" >> config.mk
fi

Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/dged/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,22 @@ struct lookup_result lookup_key(struct keymap *keymaps, uint32_t nkeymaps,
return (struct lookup_result){
.found = true,
.type = BindingType_Command,
.command = lookup_command_by_hash(commands, binding->command),
.data.command =
lookup_command_by_hash(commands, binding->data.command),
};
}
case BindingType_Keymap: {
return (struct lookup_result){
.found = true,
.type = BindingType_Keymap,
.keymap = binding->keymap,
.data.keymap = binding->data.keymap,
};
}
case BindingType_DirectCommand:
return (struct lookup_result){
.found = true,
.type = BindingType_Command,
.command = binding->direct_command,
.data.command = binding->data.direct_command,
};
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/dged/binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ enum binding_type {
#define BINDING_INNER(mod_, c_, command_) \
(struct binding) { \
.key = {.mod = mod_, .key = c_}, .type = BindingType_Command, \
.command = hash_name(command_) \
.data.command = hash_name(command_) \
}

#define ANONYMOUS_BINDING_INNER(mod_, c_, command_) \
(struct binding) { \
.key = {.mod = mod_, .key = c_}, .type = BindingType_DirectCommand, \
.direct_command = command_ \
.data.direct_command = command_ \
}

#define PREFIX_INNER(mod_, c_, keymap_) \
(struct binding) { \
.key = {.mod = mod_, .key = c_}, .type = BindingType_Keymap, \
.keymap = keymap_ \
.data.keymap = keymap_ \
}

/**
Expand Down Expand Up @@ -89,14 +89,14 @@ struct binding {
/** Type of this binding, see @ref binding_type */
uint8_t type;

union {
union binding_data {
/** A hash of a command name */
uint32_t command;
/** A command */
struct command *direct_command;
/** A keymap */
struct keymap *keymap;
};
} data;
};

/**
Expand All @@ -109,12 +109,12 @@ struct lookup_result {
/** Type of binding in the result */
uint8_t type;

union {
union lookup_data {
/** A command */
struct command *command;
/** A keymap */
struct keymap *keymap;
};
} data;
};

struct commands;
Expand Down
Loading

0 comments on commit 405da5f

Please sign in to comment.