diff options
author | pommicket <pommicket@gmail.com> | 2023-01-10 10:40:10 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-01-10 10:40:10 -0500 |
commit | b0fe15647d196081d801db574fa074ff77e46f5f (patch) | |
tree | 786d4b15493ab469811fc7cd139f5d664f414644 | |
parent | edd5188dfba93b8ffe376d0c194804f35f43dcaa (diff) |
linux build , etc.
-rw-r--r-- | CMakeLists.txt | 16 | ||||
-rw-r--r-- | Makefile | 25 | ||||
-rw-r--r-- | development.md | 38 | ||||
-rw-r--r-- | lsp.c | 3 | ||||
-rw-r--r-- | lsp.h | 2 | ||||
-rw-r--r-- | main.c | 4 | ||||
-rw-r--r-- | os-posix.c | 4 | ||||
-rw-r--r-- | stb_image.c | 18 | ||||
-rw-r--r-- | stb_truetype.c | 19 | ||||
-rw-r--r-- | util.c | 2 |
10 files changed, 99 insertions, 32 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 87d5fbb..078ed3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,11 +9,20 @@ else() set(SOURCES main.c) endif() +# make the file names absolute so we can go-to-error. +set(SOURCES_ABSOLUTE ) +foreach(SOURCE ${SOURCES}) + get_filename_component(S ${CMAKE_SOURCE_DIR}/${SOURCE} ABSOLUTE) + set(SOURCES_ABSOLUTE ${SOURCES_ABSOLUTE};${S}) +endforeach() + if (MSVC) - add_executable(ted WIN32 ${SOURCES}) + add_executable(ted WIN32 ${SOURCES_ABSOLUTE}) else() - add_executable(ted ${SOURCES}) + add_executable(ted ${SOURCES_ABSOLUTE}) endif() + + if(CMAKE_BUILD_TYPE STREQUAL "Debug") target_compile_definitions(ted PUBLIC DEBUG=1) endif() @@ -21,11 +30,12 @@ if(MSVC) 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") + set(CMAKE_C_FLAGS_DEBUG "/WX /Zi /Ob0 /Od /RTC1") set(SDL2_LIB_DIR ${CMAKE_SOURCE_DIR}/SDL2/lib/x64) target_link_libraries(ted ${SDL2_LIB_DIR}/SDL2.lib) target_link_libraries(ted ${CMAKE_SOURCE_DIR}/pcre2-32-static.lib) else() + set(CMAKE_C_FLAGS "-Wall -Wextra -Wshadow -Wconversion -Wpedantic -pedantic -std=gnu11 -Wno-unused-function -Wno-fixed-enum-extension -Wimplicit-fallthrough -Wno-format-truncation -Wno-unknown-warning-option") target_link_libraries(ted m SDL2) target_link_libraries(ted ${CMAKE_SOURCE_DIR}/libpcre2-32.a) endif() @@ -2,7 +2,6 @@ ALL_CFLAGS=$(CFLAGS) -Wall -Wextra -Wshadow -Wconversion -Wpedantic -pedantic -s -Wno-unused-function -Wno-fixed-enum-extension -Wimplicit-fallthrough -Wno-format-truncation -Wno-unknown-warning-option \ -Ipcre2 LIBS=-lSDL2 -lGL -lm libpcre2-32.a -DEBUG_CFLAGS=$(ALL_CFLAGS) -Wno-unused-parameter -DDEBUG -O0 -g RELEASE_CFLAGS=$(ALL_CFLAGS) -O3 PROFILE_CFLAGS=$(ALL_CFLAGS) -O3 -g -DPROFILE=1 # if you change the directories below, ted won't work. @@ -10,21 +9,19 @@ PROFILE_CFLAGS=$(ALL_CFLAGS) -O3 -g -DPROFILE=1 GLOBAL_DATA_DIR=/usr/share/ted LOCAL_DATA_DIR=/home/`logname`/.local/share/ted INSTALL_BIN_DIR=/usr/bin -OBJECTS=obj/buffer.o obj/build.o obj/colors.o obj/command.o\ - obj/config.o obj/find.o obj/gl.o obj/ide-autocomplete.o\ - obj/ide-definitions.o obj/ide-highlights.o obj/ide-hover.o\ - obj/ide-signature-help.o obj/ide-usages.o obj/lsp.o obj/lsp-json.o\ - obj/lsp-parse.o obj/lsp-write.o obj/main.o obj/menu.o obj/node.o\ - obj/os-posix.o obj/session.o obj/stb_image.o obj/stb_truetype.o\ - obj/syntax.o obj/tags.o obj/ted.o obj/text.o obj/ui.o obj/util.o -ted: *.[ch] libpcre2-32.a $(OBJECTS) - $(CC) $(OBJECTS) -o ted $(DEBUG_CFLAGS) $(LIBS) -obj/stb_%.o: stb_%.c - mkdir -p obj && $(CC) -O3 -Wall $< -c -o $@ -obj/%.o: %.c *.h - mkdir -p obj && $(CC) -Wall $< -c -o $@ $(DEBUG_CFLAGS) +debug-build: ted compile_commands.json +ted: debug/ted + cp debug/ted . +compile_commands.json: debug/compile_commands.json + cp debug/compile_commands.json . +debug/ted: *.[ch] libpcre2-32.a CMakeLists.txt + mkdir -p debug + cd debug && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_BUILD_TYPE=Debug .. + $(MAKE) -C debug release: *.[ch] libpcre2-32.a $(CC) main.c -o ted $(RELEASE_CFLAGS) $(LIBS) +release_debug: *.[ch] libpcre2-32.a + $(CC) main.c -g -o ted $(RELEASE_CFLAGS) $(LIBS) profile: *.[ch] libpcre2-32.a $(CC) main.c -o ted $(PROFILE_CFLAGS) $(LIBS) clean: diff --git a/development.md b/development.md index 8990218..a071b0d 100644 --- a/development.md +++ b/development.md @@ -2,12 +2,13 @@ ## 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`). +To build the debug version of ted, run `make` (or `make.bat` on Windows). -## Header files +## Files -TODO +Most function declarations should go in `ted.h`. +The exceptions are only for self-contained files, like `text.c`, +which gets its own header file `text.h`. As much as possible, OS-dependent functions should be put in `os.h/os-*.c`. (But "pure" functions like `qsort_with_context`, which could @@ -25,6 +26,11 @@ everyone the trouble...) ## Drawing +All drawing is done through either the `gl_geometry_*` functions or +the functions declared in `text.h`. +After using those functions, you need to call `gl_geometry_draw` +or `text_render` for it to actually be displayed. + ## Build details Currently, ted uses cmake for debug builds and plain old make (batch on windows) for @@ -40,9 +46,9 @@ 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. +output `compile_commands.json` which is needed for clangd. -Both `make.bat` and `Makefile` will run all the right cmake and ninja commands +Both `make.bat` and `make` will run all the right cmake and/or make and/or ninja commands for you (including generating `compile_commands.json`), so you shouldn't have to worry about that. @@ -55,11 +61,23 @@ When you add a source file to ted, make sure you: ## Adding settings +Find the `Settings` struct in `ted.h` and add the new member. +Then go to `config.c` and edit the `settings_<type>` array. + ## Adding commands +Go to `command.h` and add the command to the enum. Then +go to `command.c` and add the name of the command to the +`command_names` array, +and implement the command in the `command_execute` function. + ## Adding languages -## Syntax highlighting +Add a new member to the `Language` enum in `base.h`. +After that you should get a bunch of compiler warnings and errors +which will tell you what you need to add. + +### Syntax highlighting Obviously we don't want to re-highlight the whole file every time a change is made. Ideally, we would just re-highlight the line that was edited, but that might @@ -68,7 +86,9 @@ So we keep track of a "syntax state" for the start of each line (whether we're i whether we're in a multi-line string or not, etc.). A line's syntax highlighting can only change if it is edited, or if its syntax state changes. -## Adding LSP features +At the top of `syntax.c` there are a bunch of `SYNTAX_STATE_*` constants. +Create a new enum for your language, and add any state that needs to be remembered across lines. +Then implement the `syntax_highlight_<language>` function similar to the other ones. ## Releasing @@ -78,6 +98,6 @@ When releasing a new version of `ted`: - Update `Version` in `control` for the `.deb` file. - Run `make ted.deb` on Debian/Ubuntu. - Run `make.bat release` on Windows. -- Open installer project, and increment version number. +- Open installer project, and increase version number. - Build `ted.msi`. - Create a new release on GitHub with `ted.deb` and `ted.msi`. @@ -312,7 +312,8 @@ static bool lsp_receive(LSP *lsp, size_t max_size) { info.message); } else { lsp_set_error(lsp, "Can't access LSP server: %s\n" - "Run ted in a terminal or set lsp-log = on for more details." + "Run ted in a terminal or set lsp-log = on for more details.\n" + "Run the :lsp-reset command to restart the server." , info.message); } return false; @@ -584,7 +584,7 @@ typedef struct LSP { // dynamic array of root directories of LSP workspace folders LSPDocumentID *workspace_folders; LSPMutex error_mutex; - char error[256]; + char error[512]; } LSP; // returns true if there's an error. @@ -1,11 +1,8 @@ /* @TODO: -- 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 -- clangd bug report: - - textDocument/definition on ted.h declarations just gives you the declaration - texlab bug report: - textDocument/definition gives LocationLink regardless of client capabilities FUTURE FEATURES: @@ -17,6 +14,7 @@ FUTURE FEATURES: - make go-to-definition/hover/highlight modifier key configurable - return to previous location in buffer - font setting & support for multiple fonts to cover more characters +- support for variable-width fonts - comment-start & comment-end settings - robust find (results shouldn't move around when you type things) - open multiple files with command line arguments @@ -116,6 +116,10 @@ int os_get_cwd(char *buf, size_t buflen) { } } +int os_rename_overwrite(const char *oldname, const char *newname) { + return rename(oldname, newname) == 0 ? 0 : -1; +} + struct timespec time_last_modified(const char *filename) { struct stat statbuf = {0}; stat(filename, &statbuf); diff --git a/stb_image.c b/stb_image.c index ae13415..2badac7 100644 --- a/stb_image.c +++ b/stb_image.c @@ -1,7 +1,25 @@ // used for debug build to speed things up // just exports everything in stb_image.h + +#ifdef __GNUC__ +#define no_warn_start _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wpedantic\"") \ + _Pragma("GCC diagnostic ignored \"-Wsign-conversion\"") \ + _Pragma("GCC diagnostic ignored \"-Wsign-compare\"") \ + _Pragma("GCC diagnostic ignored \"-Wconversion\"") \ + _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"") \ + _Pragma("GCC diagnostic ignored \"-Wunused-function\"") + +#define no_warn_end _Pragma("GCC diagnostic pop") +#else +#define no_warn_start +#define no_warn_end +#endif + #define STB_IMAGE_IMPLEMENTATION #if __TINYC__ #define STBI_NO_SIMD #endif +no_warn_start #include "lib/stb_image.h" +no_warn_end diff --git a/stb_truetype.c b/stb_truetype.c index 444b245..2df7a90 100644 --- a/stb_truetype.c +++ b/stb_truetype.c @@ -1,4 +1,23 @@ // used for debug build to speed things up // just exports everything in stb_truetype.h + + +#ifdef __GNUC__ +#define no_warn_start _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wpedantic\"") \ + _Pragma("GCC diagnostic ignored \"-Wsign-conversion\"") \ + _Pragma("GCC diagnostic ignored \"-Wsign-compare\"") \ + _Pragma("GCC diagnostic ignored \"-Wconversion\"") \ + _Pragma("GCC diagnostic ignored \"-Wimplicit-fallthrough\"") \ + _Pragma("GCC diagnostic ignored \"-Wunused-function\"") + +#define no_warn_end _Pragma("GCC diagnostic pop") +#else +#define no_warn_start +#define no_warn_end +#endif + #define STB_TRUETYPE_IMPLEMENTATION +no_warn_start #include "lib/stb_truetype.h" +no_warn_end @@ -128,7 +128,7 @@ bool str_has_prefix(const char *str, const char *prefix) { bool str_has_path_prefix(const char *path, const char *prefix) { size_t prefix_len = strlen(prefix); - for (int i = 0; i < prefix_len; ++i) { + for (size_t i = 0; i < prefix_len; ++i) { if (strchr(ALL_PATH_SEPARATORS, path[i]) && strchr(ALL_PATH_SEPARATORS, prefix[i])) continue; // treat all path separators as the same if (prefix[i] != path[i]) |