diff options
| author | Albert Cervin <albert@acervin.com> | 2024-09-17 08:47:03 +0200 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2025-11-01 22:11:14 +0100 |
| commit | 4459b8b3aa9d73895391785a99dcc87134e80601 (patch) | |
| tree | a5204f447a0b2b05f63504c7fe958ef9bbf1918a /src/dged/path.c | |
| parent | 4689f3f38277bb64981fc960e8e384e2d065d659 (diff) | |
| download | dged-4459b8b3aa9d73895391785a99dcc87134e80601.tar.gz dged-4459b8b3aa9d73895391785a99dcc87134e80601.tar.xz dged-4459b8b3aa9d73895391785a99dcc87134e80601.zip | |
More lsp support
This makes the LSP support complete for now:
- Completion
- Diagnostics
- Goto implementation/declaration
- Rename
- Documentation
- Find references
Diffstat (limited to 'src/dged/path.c')
| -rw-r--r-- | src/dged/path.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/dged/path.c b/src/dged/path.c index 735ef0c..d8422f0 100644 --- a/src/dged/path.c +++ b/src/dged/path.c @@ -1,4 +1,5 @@ #include "path.h" +#include "unistd.h" #include <limits.h> #include <stdint.h> @@ -32,7 +33,37 @@ char *expanduser(const char *path) { } char *to_abspath(const char *path) { + if (strlen(path) > 0 && path[0] == '/') { + return strdup(path); + } + char *exp = expanduser(path); + if (access(path, F_OK) == -1) { + // anchor to cwd + const char *cwd = getcwd(NULL, 0); + if (cwd == NULL) { + return strdup(path); + } + + size_t cwdlen = strlen(cwd); + size_t pathlen = strlen(path); + size_t len = cwdlen + pathlen + (pathlen > 0 ? 2 : 1); + char *ret = calloc(len, sizeof(char)); + memcpy(ret, cwd, cwdlen); + + if (pathlen > 0) { + ret[cwdlen] = '/'; + memcpy(ret + cwdlen + 1, path, pathlen); + } + + ret[len - 1] = '\0'; + + free((void *)cwd); + free(exp); + + return ret; + } + char *p = realpath(path, NULL); if (p != NULL) { free(exp); |
