Skip to content

Commit 4d45818

Browse files
committed
3.1.0 Unreal source fix
1 parent 274b2e8 commit 4d45818

File tree

8 files changed

+139
-18
lines changed

8 files changed

+139
-18
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Log
22

3+
## [3.1.0] 2025-10-18
4+
### Fixed
5+
- Fixed Unreal source files not working correctly (thanks @romantimm)
6+
### Added
7+
- Added logging when adding source file to Unreal compile commands
8+
- Prompt user to remove invalid entry in Unreal's compile_commands.json
9+
310
## [3.0.2] 2025-8-30
411
### Fixed
512
- (Windows) Polling cl version now works in other languages for 'Set Custom System includes' command

FRONT.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,25 @@ This is a local copy of the front facing Docs located here: https://github.com/b
77

88
`WARNING`: Extension version `3.0.0+` has breaking changes. To upgrade version `2.0.0+` projects see section:
99

10-
- web: [Upgrading Older Projects](https://github.com/boocs/unreal-clangd?tab=readme-ov-file#upgrading-older-projects)
10+
- [Upgrading Older Projects](https://github.com/boocs/unreal-clangd?tab=readme-ov-file#upgrading-older-projects)
1111

1212
- local: [Upgrading Older Projects](#upgrading-older-projects)
1313

14+
1415
`note`: Ubuntu users: I started getting this error message wtih 5.6.0 but it still seemed to work.
1516
- Unable to watch for file changes. Please follow the instructions link to resolve this issue.
1617
- See [here](https://code.visualstudio.com/docs/setup/linux#_visual-studio-code-is-unable-to-watch-for-file-changes-in-this-large-workspace-error-enospc)
1718

19+
---
20+
---
21+
1822
# Table of Contents
1923
- [Updates](#updates)
2024
- [Important info](#important-info)
2125
- [Info](#info)
2226
- [Requirements](#requirements)
23-
- [Requirements](#requirements)
27+
- [General](#general)
28+
- [Windows](#windows)
2429
- Also see:
2530
- [Installing correct LLVM (clangd/clang) version](#installing-correct-llvm-clangdclang-version)
2631
- [Installing correct Libraries (Windows)](#installing-correct-library-versions-windows)
@@ -54,6 +59,12 @@ This is a local copy of the front facing Docs located here: https://github.com/b
5459

5560
## Updates
5661

62+
### Version 3.1.0
63+
- Fixed bug in Unreal source file support
64+
65+
#### Version 3.0.2
66+
- (Windows) Fixed Polling cl version for set custom system includes for non-English languages
67+
5768
#### Version 3.0.1
5869
- (Windows) Fixed Professional version of Visual Studio not being able to set custom system includes
5970

@@ -127,13 +138,16 @@ This extension:
127138
---
128139

129140
## Requirements
130-
#### General :
141+
#### General
131142
- Unreal v5.2+
132143
- LLVM (clang/clangd) Different Unreal versions requirement different LLVM versions (see below)
133144
- Unreal project created for VSCode
134145
- VSCode [clangd](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd) extension (Do not let the VSCode `clangd` extension auto install LLVM)
135146
- Microsoft [C++ extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) for its `Building/Debugging` Capability
136147

148+
#### Windows
149+
- Powershell 7+
150+
137151
#### Compiler and libraries :
138152
- Before explanation on getting requirements here are some useful links:
139153
- [How to install correct LLVM (clangd/clang) version](#installing-correct-llvm-clangdclang-version)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "unreal-clangd",
33
"displayName": "Unreal Clangd",
44
"description": "Creates clangd project for Unreal 5.2+",
5-
"version": "3.0.2",
5+
"version": "3.1.0",
66
"engines": {
77
"vscode": "^1.99.0"
88
},

src/extension.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11

2-
// Wait for 3.1.0
2+
3+
// Wait for 3.2.0
4+
// ***** Remove prompt to remove invalid entry in Unreal compile_commands.json
35
// Better way to backup *.code-workspace file settings?
46
// if changed Copy *.code-workspace to .vscode/unreal-clangd?
57
// Don't copy if clangd settings are missing from *.code-workspace (meaning uninstalled/not installed or improper refresh)
68
// better unreal source support
7-
// retry -mode=GenerateClangDatabase
8-
// Stopped using it because of:
9-
// Errors in response files that needed to be fixed
10-
// Would cause you to have to do a full rebuild whenever used
11-
// If we use it only for Unreal source files it shouldn't be as bad
12-
// Rarely would have to run it
13-
// That makes the problems not as bad
9+
// retry -mode=GenerateClangDatabase - this only support full source UE so maybe not...
10+
// Maybe full source unreal engine soure files only?
1411
// Create an algo to create a custom rsp file for completionHelper.cpp?
1512
// create a 2nd rsp file that lets you add customizations to the first
1613
// create algo runs on update compile command
@@ -43,6 +40,7 @@ import { addCompletionHelperToCompileCommands, FILENAME_ADD_COMPLETIONS, FILENAM
4340
import { isProjectChange, onProjectChange } from './modules/projectChange';
4441
import { startModifyResponseFiles } from './modules/modifyRspFiles';
4542
import { startCreateRspMatchers } from './modules/createRspMatchers';
43+
import { checkUnrealCompileCommands } from './modules/unrealCCChecker';
4644

4745

4846
let newSourceFilesDetectionFileWatcher: vscode.FileSystemWatcher | null = null;
@@ -343,6 +341,8 @@ export async function activate(context: vscode.ExtensionContext) {
343341
}
344342
}));
345343

344+
await checkUnrealCompileCommands();
345+
346346
const mainWorkspaceFolder = getProjectWorkspaceFolder();
347347
if(!mainWorkspaceFolder){
348348
console.error(tr.COULDNT_GET_PROJECT_WORKSPACE);

src/libs/consts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { Overwrite } from './indexTypes';
88
import type { DocumentOptions, SchemaOptions, ParseOptions, CreateNodeOptions, ToStringOptions} from 'yaml';
99
import { EOL } from "node:os";
1010

11-
export const EXTENSION_VERSION = "3.0.2";
11+
export const EXTENSION_VERSION = "3.1.0";
1212
export const VALIDATE_UNREAL_VERSIONS: { min: ueHelpers.UnrealVersion, max: ueHelpers.UnrealVersion } =
1313
{ min: { major: 5, minor: 2, patch: 0 }, max: { major: 6, minor: 0, patch: 0 } }; // The unreal versions this extension was created for
1414

src/modules/addToUeSourceCC.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import * as ueHelpers from '../libs/ueHelpers';
88
import { convertWindowsDriveLetterToUpper, getCompilerFromCompileCommands, getProjectCompileCommandsName, getValidatedCompileCommandObjectsFromUri, writeCompileCommandsFile } from '../libs/projHelpers';
99
import { getRspMatchers, restartClangd } from '../shared';
1010

11+
import * as console from '../libs/console';
12+
1113

1214
export async function startAddFilesToUESourceCompileCommands( currentDocUri: vscode.Uri) {
1315

@@ -76,6 +78,10 @@ async function addFilesToUESourceCompileCommands(
7678
return;
7779
}
7880

81+
const projectUri = ueHelpers.getProjectWorkspaceFolder()?.uri;
82+
if(!projectUri){
83+
return;
84+
}
7985
const rspPathRelative = getSourceFileRspPathMatch(ueUri, currentDocUri);
8086

8187
if(!rspPathRelative){
@@ -94,11 +100,14 @@ async function addFilesToUESourceCompileCommands(
94100
return;
95101
}
96102

97-
const ueCompileCommand = createUESourceCompileCommand(ueUri, currentDocUri.fsPath, ccCompiler, rspPathRelative);
103+
const ueCompileCommand = createUESourceCompileCommand(ueUri, projectUri, currentDocUri.fsPath, ccCompiler, rspPathRelative);
98104

99105
ueSelfCompileCommands.push(ueCompileCommand);
100106

101107
if (friendFileInfo === undefined) {
108+
console.log(`Adding file to UE compile commands: ${currentDocUri.fsPath}`);
109+
console.log(` Relative rsp path: ${rspPathRelative}`);
110+
102111
const friendUri: vscode.Uri | undefined = await findFriendUri(currentDocUri);
103112
if (friendUri) {
104113
await addFilesToUESourceCompileCommands(ueUri, friendUri, { origCC: ueSelfCompileCommands, compiler: ccCompiler });
@@ -108,6 +117,7 @@ async function addFilesToUESourceCompileCommands(
108117

109118
}
110119

120+
return;
111121
}
112122

113123

@@ -131,7 +141,9 @@ function getSourceFileRspPathMatch( parentUri: vscode.Uri, fileUri: vscode.Uri){
131141

132142
const rspMatcherPaths: {rspPath: string, closeness: number}[] = [];
133143

134-
for (const matcher of getRspMatchers()) {
144+
const rspMatchers = getRspMatchers();
145+
146+
for (const matcher of rspMatchers) {
135147
const dirPath = vscode.Uri.joinPath(parentUri, matcher.ueDirRelative);
136148
const pathTest = nodePath.relative(dirPath.fsPath, fileUri.fsPath);
137149

@@ -173,9 +185,9 @@ function getSourceFileRspPathMatch( parentUri: vscode.Uri, fileUri: vscode.Uri){
173185
}
174186

175187

176-
function createUESourceCompileCommand(ueUri: vscode.Uri, file: string, compilerPath: string, rspRelative: string): CompileCommand {
188+
function createUESourceCompileCommand(ueUri: vscode.Uri, projectUri: vscode.Uri, file: string, compilerPath: string, rspRelative: string): CompileCommand {
177189
const ccDirectory = vscode.Uri.joinPath(ueUri, consts.FOLDER_NAME_ENGINE, consts.FOLDER_NAME_SOURCE);
178-
const rspPath = vscode.Uri.joinPath(ueUri, rspRelative);
190+
const rspPath = vscode.Uri.joinPath(projectUri, rspRelative);
179191

180192
return {
181193
file: convertWindowsDriveLetterToUpper(file),

src/modules/createRspMatchers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async function createRspMatchers(progress: vscode.Progress<{
5050
progress.report({increment:increment});
5151

5252
const rspName = nodePath.parse(extraction.uri.fsPath).name.split('.')[0];
53-
const rspRelative = nodePath.relative(ueUri.fsPath, extraction.uri.fsPath);
53+
const rspRelative = nodePath.relative(projUri.fsPath, extraction.uri.fsPath);
5454

5555
const ueDirPath = nodePath.dirname(extraction.extracted[0]);
5656
const ueDirRelPath = nodePath.relative(ueUri.fsPath, ueDirPath);

src/modules/unrealCCChecker.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import * as vscode from 'vscode';
2+
3+
import { getUnrealClangdCompileCommandsUri, getValidatedCompileCommandObjectsFromUri, isFile, writeCompileCommandsFile } from "../libs/projHelpers";
4+
import { getUnrealUri } from "../libs/ueHelpers";
5+
import * as console from '../libs/console';
6+
import type { CompileCommand } from "../libs/types";
7+
import { restartClangd } from '../shared';
8+
9+
export async function checkUnrealCompileCommands() {
10+
console.log("Checking Unreal compile commands...");
11+
12+
const ueUri = getUnrealUri();
13+
if (!ueUri) {
14+
return;
15+
}
16+
17+
const ueClangdCCUri = getUnrealClangdCompileCommandsUri(ueUri, { withFileName: true });
18+
19+
// Get ccs from file
20+
const ccs = await getValidatedCompileCommandObjectsFromUri(ueClangdCCUri);
21+
if (!ccs) {
22+
console.error("Couldn't get Unreal compile commands object");
23+
return;
24+
}
25+
26+
// Get ccs with invalid removed or ignored
27+
const newCcs = await getCCWithValidResponseFiles(ccs);
28+
29+
// Don't do anything
30+
if (!newCcs) {
31+
console.log("No invalid Unreal compile commands found or were ignored.");
32+
return;
33+
}
34+
35+
console.log(`Writing fixed Unreal compile commands: ${ueClangdCCUri.fsPath}`);
36+
await writeCompileCommandsFile(ueClangdCCUri, undefined, newCcs);
37+
38+
await restartClangd();
39+
}
40+
41+
42+
async function getCCWithValidResponseFiles(ccs: CompileCommand[]) {
43+
44+
const returnCompileCommands: CompileCommand[] = [];
45+
46+
let fileIsDirty = false;
47+
let choice: "Remove" | "Remove All" | "Keep" | undefined = undefined;
48+
49+
for (const cc of ccs) {
50+
const rspPath = cc.arguments?.[1].slice(1);
51+
if (!rspPath) {
52+
continue;
53+
}
54+
55+
if (await isFile(vscode.Uri.file(rspPath))) {
56+
returnCompileCommands.push(cc);
57+
continue;
58+
}
59+
60+
// Not a file so ask to delete or keep or delete all invalid
61+
if (choice !== "Remove All") {
62+
console.error(`Unreal CC invalid rsp path found! ${rspPath}`);
63+
choice = await vscode.window.showErrorMessage(
64+
`Invalid path found in Unreal's compile_commands.json!\n\nRSP Path:\n${rspPath}`,
65+
{ detail: "What would you like to do with this invalid path?", modal: true },
66+
"Remove", "Remove All", "Keep"
67+
);
68+
}
69+
70+
if (!choice) {
71+
break;
72+
}
73+
74+
if (choice === "Keep") {
75+
returnCompileCommands.push(cc);
76+
continue;
77+
}
78+
79+
fileIsDirty = true;
80+
}
81+
82+
if (!choice || !fileIsDirty) {
83+
return;
84+
}
85+
86+
return returnCompileCommands;
87+
88+
}

0 commit comments

Comments
 (0)