Skip to content

Commit 322cfb2

Browse files
committed
[config][relative] Convert relative "extra paths" to absolute
Also fixes a infinite loop which occured with relative paths.
1 parent 7fdc9ba commit 322cfb2

5 files changed

Lines changed: 22 additions & 20 deletions

File tree

doc/user-manual.adoc

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,44 +38,43 @@ If no config file could be found, you'll be prompted to create a project. The ac
3838

3939
=== Project Configuration
4040

41-
The `.c-xrefrc` file defines which files belong to the project. A minimal config
42-
looks like:
41+
The `.c-xrefrc` file marks the root of a source tree. The directory containing
42+
`.c-xrefrc` and its subdirectories are always scanned for compilation units. A
43+
minimal config only needs a section header naming the project:
4344

4445
[source]
4546
----
46-
[/path/to/project]
47-
/path/to/project
47+
[my-project]
4848
----
4949

50-
The section header `[...]` names the project (typically the project root path).
50+
The section header `[...]` names the project.
5151
Lines below it configure the project:
5252

53-
Source directories:: Bare path lines list directories to scan for compilation units.
54-
The project root is always scanned. Additional directories can be listed for
55-
multi-directory or multi-repo projects:
53+
Source directories:: The project root (where `.c-xrefrc` lives) and its
54+
subdirectories are always scanned automatically. Additional source directories
55+
only need to be listed for multi-directory projects, e.g. when source files
56+
live outside the project root:
5657
+
5758
[source]
5859
----
59-
[/path/to/project]
60-
/path/to/project
61-
/path/to/shared/library
60+
[my-project]
61+
../shared/library
6262
----
6363

6464
Include paths:: `-I` options tell c-xrefactory where to find header files, just
6565
like the compiler flag:
6666
+
6767
[source]
6868
----
69-
[/path/to/project]
70-
/path/to/project
71-
-I /path/to/external/headers
69+
[my-project]
70+
-I ../external/headers
7271
----
7372

7473
Preprocessor defines:: `-D` options define macros, equivalent to the compiler flag.
7574
Useful when the project uses conditional compilation.
7675

77-
TIP: For projects that use auto-detection (project-local `.c-xrefrc`), absolute paths
78-
are not required — the configuration is resolved relative to the file's location.
76+
TIP: Paths in `.c-xrefrc` are resolved relative to the config file's directory,
77+
so the configuration is portable and can be checked into version control.
7978

8079
== Browsing
8180

src/editorbuffer.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ EditorBuffer *newEditorBuffer(char *realFileName, int fileNumber, char *preLoade
3939

4040
EditorBuffer *createNewEditorBuffer(char *realFileName, char *preLoadedFromFile, time_t modificationTime,
4141
size_t size) {
42-
char safeFileName[MAX_FILE_NAME_SIZE];
43-
strcpy(safeFileName, realFileName);
44-
char *normalizedRealFileName = strdup(normalizeFileName_static(safeFileName, cwd));
42+
char *normalizedRealFileName = strdup(normalizeFileName_static(realFileName, cwd));
4543

4644
assert(preLoadedFromFile == NULL || strcmp(realFileName, preLoadedFromFile) != 0);
4745
char *normalizedLoadedFromFile = NULL;

src/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "lsp.h"
1313
#include "memory.h"
1414
#include "proto.h"
15+
#include "refactory.h"
1516
#include "server.h"
1617
#include "stackmemory.h"
1718
#include "startup.h"

src/projectstructure.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "stringlist.h"
1010
#include "yylex.h"
1111

12+
1213
#define SCAN_BUFFER_SIZE 4096
1314

1415
/* Resolve an include path: try includer's directory first, then walk

src/startup.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,12 @@ static void loadProjectSettings(ArgumentsVector baseArgs, ArgumentsVector reques
550550
{
551551
ArgumentsVector configArgs = readOptionsFromFile(projectConfigFileName,
552552
projectSectionName, projectSectionName);
553+
char *configDir = directoryName_static(projectConfigFileName);
553554
for (int i = 1; i < configArgs.argc; i++) {
554555
if (configArgs.argv[i][0] != '-') {
555-
projectConfig.sourceDirs = newStringList(configArgs.argv[i],
556+
char absolutePath[MAX_FILE_NAME_SIZE];
557+
strcpy(absolutePath, normalizeFileName_static(configArgs.argv[i], configDir));
558+
projectConfig.sourceDirs = newStringList(absolutePath,
556559
projectConfig.sourceDirs);
557560
}
558561
}

0 commit comments

Comments
 (0)