summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--CMakeLists.txt19
-rw-r--r--README.md9
-rw-r--r--buffer.c6
-rw-r--r--development.md48
-rw-r--r--main.c18
-rw-r--r--make.bat1
7 files changed, 81 insertions, 22 deletions
diff --git a/.gitignore b/.gitignore
index 9046bce..c770116 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,3 +30,5 @@ test.txt
log.txt
UpgradeLog.htm
compile_commands.json
+# clangd creates .cache on windows at least
+.cache
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d1a59e7..87d5fbb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,17 +1,24 @@
cmake_minimum_required(VERSION 3.1)
project(ted)
-set(SOURCES buffer.c build.c colors.c command.c config.c find.c gl.c ide-autocomplete.c
- ide-definitions.c ide-highlights.c ide-hover.c ide-signature-help.c ide-usages.c
- lsp.c lsp-json.c lsp-parse.c lsp-write.c main.c menu.c node.c os.c session.c
- stb_image.c stb_truetype.c syntax.c tags.c ted.c text.c ui.c util.c)
+if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+ set(SOURCES buffer.c build.c colors.c command.c config.c find.c gl.c ide-autocomplete.c
+ ide-definitions.c ide-highlights.c ide-hover.c ide-signature-help.c ide-usages.c
+ lsp.c lsp-json.c lsp-parse.c lsp-write.c main.c menu.c node.c os.c session.c
+ stb_image.c stb_truetype.c syntax.c tags.c ted.c text.c ui.c util.c)
+else()
+ set(SOURCES main.c)
+endif()
+
if (MSVC)
add_executable(ted WIN32 ${SOURCES})
else()
add_executable(ted ${SOURCES})
endif()
-target_compile_definitions(ted PUBLIC DEBUG=1)
+if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+ target_compile_definitions(ted PUBLIC DEBUG=1)
+endif()
if(MSVC)
- target_sources(ted PRIVATE ted.res)
+ target_sources(ted PRIVATE ted.rc)
target_include_directories(ted PUBLIC ${CMAKE_SOURCE_DIR}/SDL2/include ${CMAKE_SOURCE_DIR}/pcre2)
set(CMAKE_C_FLAGS "/MD /W4 /wd4200 /wd4204 /wd4221 /wd4706 /wd4214 /D_CRT_SECURE_NO_WARNINGS")
set(CMAKE_C_FLAGS_DEBUG "/Zi /Ob0 /Od /RTC1")
diff --git a/README.md b/README.md
index e2ccdf8..ecc1d50 100644
--- a/README.md
+++ b/README.md
@@ -133,12 +133,6 @@ ted has support for [LSPs](https://microsoft.github.io/language-server-protocol/
You can Ctrl+Click on an identifier to go to its definition, or Ctrl+Shift+Click to go
to its declaration, or Ctrl+Alt+Click to go to its type's definition.
-(clangd seems to sometimes go to the declaration even
-when the definition should be available, e.g.
-when Ctrl+clicking on the function declarations
-in `ted.h`. This is Not My Fault,
-and VSCode's clangd extension suffers from the same problem.)
-
You can also press Ctrl+D to get a searchable list of all functions/types where you can select one to go to
its definition.
@@ -177,6 +171,9 @@ sudo apt install clangd-15 # replace 15 with the highest number you can get
sudo ln -s /usr/bin/clangd-15 /usr/bin/clangd
```
+For "go to definition" and "find usages" to work properly, you may need to
+create a compile\_commands.json file.
+
### Go
The Go team's `go-pls` is enabled by default. You can download it
diff --git a/buffer.c b/buffer.c
index 607f250..c00d20b 100644
--- a/buffer.c
+++ b/buffer.c
@@ -2326,6 +2326,12 @@ Status buffer_load_file(TextBuffer *buffer, const char *path) {
if (success) {
char *path_copy = buffer_strdup(buffer, path);
if (!path_copy) success = false;
+ #if _WIN32
+ // only use \ as a path separator
+ for (char *p = path_copy; *p; ++p)
+ if (*p == '/')
+ *p = '\\';
+ #endif
if (success) {
// everything is good
buffer_clear(buffer);
diff --git a/development.md b/development.md
index f983d39..8990218 100644
--- a/development.md
+++ b/development.md
@@ -1,20 +1,58 @@
(work in progress)
+## Building
+
+To build the debug version of `ted`, you will need ninja-build (package `ninja` on Debian/Ubuntu).
+On Windows you don't need to install it since it comes with MSVC. Then run just `make` (or `make.bat`).
+
+## Header files
+
+TODO
+
As much as possible, OS-dependent functions should be put in `os.h/os-*.c`.
(But "pure" functions like `qsort_with_context`, which could
in theory be implemented on any platform with just plain C, should be put
in `util.c` even if they use OS-specific library functions.)
-## Header files
-
## Unicode
-- UTF-32
-- codepoints are characters
-- stuff outside BMP on windows
+ted stores text as UTF-32. We assume that code points are characters.
+This is not correct for combining diacritics and will hopefully be fixed at some point.
+
+All paths are stored as UTF-8, and annoyingly have to be converted to UTF-16 for Windows
+functions (why hasn't Windows made UTF-8 versions of all their API functions yet to save
+everyone the trouble...)
## Drawing
+## Build details
+
+Currently, ted uses cmake for debug builds and plain old make (batch on windows) for
+release builds. My hope is that `ted` will always be compilable with:
+```
+cc main.c
+```
+Of course this is not possible because ted uses libraries. But at least we have
+```
+cc main.c libpcre.a -lSDL2 -lm
+```
+or something.
+
+
+I don't like complicated build systems, and I'm only using cmake because it can
+(through ninja) output `compile_commands.json` which is used for clangd.
+
+Both `make.bat` and `Makefile` will run all the right cmake and ninja commands
+for you (including generating `compile_commands.json`),
+so you shouldn't have to worry about that.
+
+## Adding source files
+
+When you add a source file to ted, make sure you:
+
+1. `#include` it in main.c
+2. Add it to the `SOURCES` variable in CMakeLists.txt
+
## Adding settings
## Adding commands
diff --git a/main.c b/main.c
index 21a53d6..90d273a 100644
--- a/main.c
+++ b/main.c
@@ -1,10 +1,6 @@
/*
@TODO:
-- make sure buffer_load_file/buffer_new_file handle paths with forward slashes on windows
-- why are all requests failing on windows?
-- are we freeing process if process_run(_ex) fails?
-- test time_last_modified (windows)
-- add note to README about compile_commands.json
+- get Makefile to use ninja
- rust-analyzer bug reports:
- bad json can give "Unexpected error: client exited without proper shutdown sequence"
- containerName not always given in workspace/symbols
@@ -247,7 +243,18 @@ static LONG WINAPI error_signal_handler(EXCEPTION_POINTERS *info) {
} else {
die(CRASH_STARTUP_MESSAGE);
}
+
+ // MSVC is smart here and realizes this code is unreachable.
+ // that said, I'm worried about not returning a value here for older MSVC versions
+ // and just in general.
+ #if _MSC_VER
+ #pragma warning(push)
+ #pragma warning(disable:4702)
+ #endif
return EXCEPTION_EXECUTE_HANDLER;
+ #if _MSC_VER
+ #pragma warning(pop)
+ #endif
}
#endif
@@ -309,6 +316,7 @@ int main(int argc, char **argv) {
command_init();
color_init();
+
// read command-line arguments
const char *starting_filename = NULL;
switch (argc) {
diff --git a/make.bat b/make.bat
index c43974c..7379c56 100644
--- a/make.bat
+++ b/make.bat
@@ -13,6 +13,7 @@ if not exist pcre2-32-static.lib (
SET C_FLAGS=/nologo /W4 /MD /wd4200 /wd4204 /wd4221 /wd4706 /wd4214 /D_CRT_SECURE_NO_WARNINGS /I SDL2/include /I pcre2 SDL2/lib/x64/SDL2main.lib SDL2/lib/x64/SDL2.lib pcre2-32-static.lib
rc /nologo ted.rc
if _%1 == _ (
+ if not exist debug mkdir debug
pushd debug
cmake -DCMAKE_BUILD_TYPE=Debug -GNinja ..
ninja