Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit a313819

Browse files
committed
Stop using -fdiagnostics-absolute-paths
It seems that the `-fdiagnostics-absolute-paths` flag was only introduced in LLVM v4.0.0, as such the usage of this flag was breaking this package for all users on an older version of LLVM. Move to parsing the relative paths coming from `clang` based on the working directory, attempting to handle relative directory overrides coming from clang-complete as well.
1 parent c4b7025 commit a313819

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

lib/main.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// eslint-disable-next-line import/extensions, import/no-extraneous-dependencies
44
import { CompositeDisposable } from 'atom';
5-
import { dirname, extname } from 'path';
5+
import { dirname, extname, resolve, isAbsolute } from 'path';
66

77
let helpers = null;
88
let clangFlags = null;
@@ -162,11 +162,11 @@ export default {
162162
const fileExt = extname(filePath);
163163
const fileDir = dirname(filePath);
164164
const fileText = editor.getText();
165+
let basePath;
165166

166167
const args = [
167168
'-fsyntax-only',
168169
'-fno-color-diagnostics',
169-
'-fdiagnostics-absolute-paths',
170170
'-fdiagnostics-parseable-fixits',
171171
'-fdiagnostics-print-source-range-info',
172172
'-fexceptions',
@@ -217,10 +217,14 @@ export default {
217217
let usingClangComplete = false;
218218
try {
219219
const flags = clangFlags.getClangFlags(filePath);
220-
if (flags.length > 0) {
221-
args.push(...flags);
220+
flags.forEach((flag) => {
221+
args.push(flag);
222222
usingClangComplete = true;
223-
}
223+
const workingDir = /-working-directory=(.+)/.exec(flag);
224+
if (workingDir !== null) {
225+
basePath = workingDir[1];
226+
}
227+
});
224228
} catch (error) {
225229
if (atom.inDevMode()) {
226230
// eslint-disable-next-line no-console
@@ -245,6 +249,7 @@ export default {
245249
args.push('-');
246250
execOpts.stdin = fileText;
247251
execOpts.cwd = fileDir;
252+
basePath = fileDir;
248253
}
249254

250255
const output = await helpers.exec(this.executablePath, args, execOpts);
@@ -260,7 +265,14 @@ export default {
260265
while (match !== null) {
261266
const isCurrentFile = match[1] === '<stdin>';
262267
// If the "file" is stdin, override to the current editor's path
263-
const file = isCurrentFile ? filePath : match[1];
268+
let file;
269+
if (isCurrentFile) {
270+
file = filePath;
271+
} else if (isAbsolute(match[1])) {
272+
file = match[1];
273+
} else {
274+
file = resolve(basePath, match[1]);
275+
}
264276
let position;
265277
if (match[4]) {
266278
// Clang gave us a range, use that
@@ -270,7 +282,7 @@ export default {
270282
const line = Number.parseInt(match[2], 10) - 1;
271283
const col = Number.parseInt(match[3], 10) - 1;
272284
if (!isCurrentFile) {
273-
const fileEditor = findTextEditor(match[1]);
285+
const fileEditor = findTextEditor(file);
274286
if (fileEditor !== false) {
275287
// Found an open editor for the file
276288
position = helpers.generateRange(fileEditor, line, col);

0 commit comments

Comments
 (0)