Skip to content

Commit 1fd51aa

Browse files
committed
2.5.0 Native Intellisense
1 parent 1814677 commit 1fd51aa

File tree

11 files changed

+1388
-327
lines changed

11 files changed

+1388
-327
lines changed

.eslintrc.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@
33
"parser": "@typescript-eslint/parser",
44
"parserOptions": {
55
"ecmaVersion": 6,
6-
"sourceType": "module"
6+
"sourceType": "module",
7+
"project": "./tsconfig.json"
78
},
89
"plugins": [
910
"@typescript-eslint"
1011
],
12+
"extends": [
13+
//"eslint:recommended",
14+
//"plugin:@typescript-eslint/recommended"
15+
//"plugin:@typescript-eslint/recommended-requiring-type-checking"
16+
],
1117
"rules": {
1218
"@typescript-eslint/naming-convention": "warn",
1319
"@typescript-eslint/semi": "warn",
20+
//"@typescript-eslint/await-thenable": "error",
1421
"curly": "warn",
1522
"eqeqeq": "warn",
1623
"no-throw-literal": "warn",

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44

55
- Create command that shows clang and clangd version in terminal
66

7+
## [2.5.0] 2024-05-05
8+
### Changed
9+
- Moved to using a project's Native Intellisense files instead of using UBT's mode=GenerateClangDataBase
10+
- mode=GenerateClangDataBase was overwriting build files causing you to have to rebuild
11+
- In .clangd, CompilationDatabase is now a relative path(set during creation process)
12+
### Added
13+
- Native - Removed PCH header from Intellisense files. Not needed and increases intellisense loading greatly.
14+
- Native - Setting: unreal-clangd.IntellisenseType. This is always set to 'Native' even if switched.
15+
- Native - Setting: unreal-clangd.native.minutesTillIntellisenseFilesAreOld
16+
- Can cause circular run of Update Compile Commands if set too low. You can also run Update Compile Commands manually if you run into trouble with it being too high.
17+
- Native - Setting: unreal-clangd.native.code-workspaceFileBackupSettings
18+
- Array so you can specify which settings to backup in your *.code-workspace file when the native `Update Compile Commands` is run. This runs UBT's 'refresh project files' command that will overwrite your *code.workspace file. Some settings will automatically be backed up and are listed in your settings.
19+
### Removed
20+
- -D\_\_INTELLISENSE\_\_ from .clangd (always muddled on if I should include it). 5.4 forced me to remove it since it caused a error if enabled.
21+
### Fixed
22+
- Code that added compiler flags to eventually go in .clangd
23+
724
## [2.3.0] 2024-01-21
825
### Added
926
- clang-format: added "NamespaceIndentation: All" to default config when created

README.md

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

44
# Unreal 5.2+ clangd extension for VSCode
5-
#### `(Supports any Unreal version >= 5.2)`
5+
#### `(Supports any Unreal version >= 5.2)` This version has been updated for 5.4+ support
66

77
[https://github.com/boocs/unreal-clangd](https://github.com/boocs/unreal-clangd)
88

@@ -310,13 +310,16 @@ https://docs.unrealengine.com/5.3/en-US/hardware-and-software-specifications-for
310310

311311
3. Scroll down to all the listings for **MSVC v143 - VS 2022 C++ x64/x86 build tools**
312312

313-
For `Unreal 5.2` you want to enable `v14.34`:
313+
* For `Unreal 5.2` you want to enable `v14.34`:
314314

315-
![image](https://github.com/boocs/unreal-clangd/assets/62588629/b5d8f068-8e77-43f0-b68d-7f390f007d4c)
315+
![image](https://github.com/boocs/unreal-clangd/assets/62588629/b5d8f068-8e77-43f0-b68d-7f390f007d4c)
316316

317-
For `Unreal 5.3` you want to enable `v14.36`:
317+
* For `Unreal 5.3` you want to enable `v14.36`:
318318

319-
![image](https://github.com/boocs/unreal-clangd/assets/62588629/aec88536-557e-4171-96c3-c73d8dc15766)
319+
![image](https://github.com/boocs/unreal-clangd/assets/62588629/aec88536-557e-4171-96c3-c73d8dc15766)
320+
321+
* For `Unreal 5.4` you want to enable `v14.38`
322+
- (Pic not shown)
320323

321324
4. If you haven't created your Unreal project yet you can skip steps 5/6
322325
5. For existing Unreal projects, first Refresh your project (this will overwrite your workspace file which we fix in step 6)
@@ -362,7 +365,7 @@ The other reason was a Unreal design change. 5.0.0 uses compile commands while 5
362365
* `unreal-clangd.createUnrealClangdProject`: Creates all files and settings for clangd to work with an Unreal project
363366
* `unreal-clangd.updateCompileCommands`: Creates/Updates the compile commands file which clangd uses for Intellisense. Created in project/.vscode folder. **(Extension will, in most cases, prompt you to update automatically)**
364367
* `unreal-clangd.uninstall`: Uninstalls Unreal-clangd files and settings **(It will prompt you before deletion)**
365-
* `unreal-clangd.fixQuotesResponseFiles`: Runs the quote fix for paths in response files **(Will auto run if setting is true)**
368+
* `unreal-clangd.fixIntellisenseFiles`: Runs the quote fix for paths in response files **(Will auto run if setting is true)**
366369
* `unreal-clangd.tidyNoLintCurrentLine`: Removes clang Tidy linting on current line
367370
- **Modifies code**
368371
- **Also found in context menu**
@@ -377,6 +380,13 @@ The other reason was a Unreal design change. 5.0.0 uses compile commands while 5
377380
```
378381

379382
### Settings
383+
384+
* `unreal-clangd.IntellisenseType`: This is always set to 'Native' even if switched (for now)
385+
#### Native
386+
* `unreal-clangd.native.minutesTillIntellisenseFilesAreOld`:
387+
- Can cause circular run of Update Compile Commands if set too low. You can also run Update Compile Commands manually if you run into trouble with it being too high.
388+
* `unreal-clangd.native.code-workspaceFileBackupSettings`:
389+
- Array so you can specify which settings to backup in your *.code-workspace file when the native `Update Compile Commands` is run. This runs UBT's 'refresh project files' command that will overwrite your *code.workspace file. Some settings will automatically be backed up and are listed in your settings.
380390
#### Compile Commands
381391
* `unreal-clangd.compileCommands.execType`: Task | Debug
382392
- **Debug requires Microsoft C# extension which lets you see UBT logs**
@@ -399,7 +409,7 @@ The other reason was a Unreal design change. 5.0.0 uses compile commands while 5
399409
- Also activates when copying and pasting a function
400410

401411
#### Fixes
402-
* `unreal-clangd.fixes.responseFilesQuotedPaths`: Enables/disables fix that automatically puts quotes around paths in all response files used by Intellisense. **(This will auto fix whenever it detects compile command changes)**
412+
* `unreal-clangd.fixes.intellisenseFiles`: Enables/disables Change or fix intellisense files when needed. **(This will auto fix whenever it detects compile command changes)**
403413
* `unreal-clangd.fixes.delegateFunctionCompletions`: Some delegate functions completions aren't correct because of macro expansion. This will fix the completion when detected.
404414
- See [this](#delegate-function-name-completions) section for more info
405415
* `unreal-clangd.fixes.focusSuggestionDelay`: Fixes code completion selection not happening with parameter hints. Default 350 [see section](#function-parameter-completions)
@@ -555,14 +565,15 @@ Click the console 'OUTPUT' tab and change the top right drop down to 'unreal cla
555565
* ![](https://user-images.githubusercontent.com/62588629/233814109-2ff37ccf-faaa-4fc0-bf77-e9e85bfa6120.png)
556566
```
557567
```
568+
### Clangd Project Files
569+
558570
### **.clangd file**
559571
Lets you Add/Remove Intellisense compile flags that clang uses, among other things. See [clangd docs.](https://clangd.llvm.org/config)
560572
561573
**note:** A lot of functionality was added with clangd-14 so won't work wth earlier versions
562574
563575
564-
```
565-
```
576+
566577
### **.clang-format file**
567578
568579
The clangd extension will take over formatting of your C++ documents.
@@ -575,8 +586,7 @@ This extension creates a bare minimum format file that makes code look pretty go
575586
576587
For more format settings info: https://clang.llvm.org/docs/ClangFormatStyleOptions.html
577588
578-
```
579-
```
589+
580590
### **.clang-tidy file**
581591
Used for the C++ linter. You can see the docs [here](https://clang.llvm.org/extra/clang-tidy/)
582592
@@ -609,6 +619,7 @@ The file is located in your project's parent folder.
609619
610620
`Warning`: Using the Unreal Engine's `Refresh Visual Studio Project` or `Generate Visual Studio Project files` command will overwrite this file. See [this](#refresh-visual-studio-project) section.
611621
622+
612623
```
613624
```
614625
@@ -793,9 +804,7 @@ Thanks to Mark at [stackoverflow](https://stackoverflow.com/a/76096050/13950944)
793804
```
794805
### Linux Fixes
795806
796-
Simple fix is to include /usr/include using -isystem
797-
798-
- This is `automatically fixed` in the .clangd file that is created for your project.
807+
Check the .clangd project file 'Add' section for all the fixes applied.
799808
800809
```
801810
```
@@ -1225,17 +1234,8 @@ https://github.com/electron/electron/issues/32857
12251234
```
12261235
```
12271236
### Installing Microsoft C++ Extension After Install
1228-
It's faster not to recreate a project of this extension, with the 'lazy' setting, and just set the correct settings manually.
12291237
1230-
1. Go to your project's .vscode directory
1231-
2. Open settings.json
1232-
3. Paste these settings in:
1233-
```
1234-
"C_Cpp.autocomplete": "disabled",
1235-
"C_Cpp.errorSquiggles": "disabled",
1236-
"C_Cpp.formatting": "disabled",
1237-
"C_Cpp.intelliSenseEngine": "disabled"
1238-
```
1238+
The extension `now detects` that the Microsoft C++ extension is installed and will auto set correct settings on startup or reload.
12391239
12401240
```
12411241
```

package.json

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "unreal-clangd",
33
"displayName": "Unreal Clangd",
44
"description": "clangd helper for UE 5.2+",
5-
"version": "2.3.0",
5+
"version": "2.5.0",
66
"engines": {
77
"vscode": "^1.77.3"
88
},
@@ -37,9 +37,8 @@
3737
"category": "unreal clangd"
3838
},
3939
{
40-
"command": "unreal-clangd.fixQuotesResponseFiles",
41-
"title": "Fix paths in response files by surrounding them with quotes",
42-
"shortTitle": "Fix paths in response files",
40+
"command": "unreal-clangd.fixIntellisenseFiles",
41+
"title": "Fix quotes in gcd(Intellisense) files.",
4342
"category": "unreal clangd"
4443
},
4544
{
@@ -72,10 +71,39 @@
7271
{
7372
"title": "Unreal Clangd",
7473
"properties": {
75-
"unreal-clangd.fixes.responseFilesQuotedPaths": {
74+
"unreal-clangd.IntellisenseType": {
75+
"type": "string",
76+
"default": "Native",
77+
"readOnly": true,
78+
"enum": [
79+
"Native",
80+
"GenerateClangDataBase"
81+
],
82+
"markdownEnumDescriptions": [
83+
"Uses your project's native Intellisense files",
84+
"Uses GenerateClangDataBase for Intellisense `(currently unavailable)`"
85+
],
86+
"description": "Which Intellisense files to use for your project.",
87+
"scope": "resource",
88+
"order": 0
89+
},
90+
"unreal-clangd.native.code-workspaceFileBackupSettings": {
91+
"type": "array",
92+
"markdownDescription": "Any setting you want backed up when running the Native \"Update Intellisense Files\" command.\nRunning this `Unreal Build Tool's` command refreshes your project causing the project's `*.code-workspace` file to be overwritten.\n These settings will automatically be backed up: `clangd.arguments`, `clangd.path`, `clangd.detectExtensionConflicts`, `files.associations`, `workbench.colorCustomizations`, `editor.suggestFontSize`, `dotnet.defaultSolution`\n* `note:` Do not set in a config that Unreal overwrites!",
93+
"scope": "resource",
94+
"order": 1
95+
},
96+
"unreal-clangd.native.minutesTillIntellisenseFilesAreOld": {
97+
"type": "number",
98+
"default": 5,
99+
"markdownDescription": "Minutes till intellisense files are considered old.\n* Doesn't affect manually running `Update Compile Commands` command.\n* When adding multiple Source files the 'auto-detect and run' `Update Compile Commands` command might not run so run command manually.",
100+
"scope": "resource",
101+
"order": 1
102+
},
103+
"unreal-clangd.fixes.intellisenseFiles": {
76104
"type": "boolean",
77105
"default": true,
78-
"description": "In reponse files, surrounds paths with quotes.",
106+
"description": "Fixes Intellisense files when they have errors or need changes.",
79107
"scope": "resource"
80108
},
81109
"unreal-clangd.fixes.delegateFuncCompletions": {

src/dynamic.ts

Lines changed: 82 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import * as vscode from "vscode";
22
import * as consts from "./libs/consts";
33

44
import { UnrealPlatform } from "./libs/indexTypes";
5-
import { AllDefaultSettings, ClangdCfgFileSettings, ExtensionYamlFiles } from "./libs/types";
5+
import { AllDefaultSettings, ClangdCfgFileSettings, ExtensionYamlFiles, ExtensionIntellisenseType} from "./libs/types";
6+
import { UnrealVersion } from "./libs/ueHelpers";
67

78

8-
export function addDynamicDefaultSettingsToConfig(mainWorkspace: vscode.WorkspaceFolder, configSettings: AllDefaultSettings, clangdPath: string, compileCommandsDirUri: vscode.Uri | undefined): boolean {
9+
export function addDynamicDefaultSettingsToConfig(ueVersion: UnrealVersion | undefined, clangdExtYamlFiles: ExtensionYamlFiles, configSettings: AllDefaultSettings, clangdPath: string, compileCommandsDirUri: vscode.Uri | undefined): boolean {
910

1011
if (!clangdPath) {
1112
console.error("No clangd paths found!");
@@ -24,22 +25,76 @@ export function addDynamicDefaultSettingsToConfig(mainWorkspace: vscode.Workspac
2425
console.error("Couldn't get clangd settings path.");
2526
return true;
2627
}
28+
29+
if(!ueVersion){
30+
console.error("Couldn't get UE version!");
31+
return true;
32+
}
33+
34+
let cppVersion = "";
35+
36+
if(process.platform === "win32") {
37+
cppVersion = consts.NATIVE_WIN_CLANGD_ADD_STD_CPP20;
38+
}
39+
else {
40+
cppVersion = consts.NATIVE_NON_WIN_CLANGD_ADD_STD_CPP20;
41+
}
42+
43+
44+
if(ueVersion.major === 5 && ueVersion.minor < 2){
45+
if(process.platform === "win32") {
46+
cppVersion = consts.NATIVE_WIN_CLANGD_ADD_STD_CPP17;
47+
}
48+
else {
49+
cppVersion = consts.NATIVE_NON_WIN_CLANGD_ADD_STD_CPP17;
50+
}
51+
}
52+
53+
if(ueVersion.major === 4){
54+
if(process.platform === "win32") {
55+
cppVersion = consts.NATIVE_WIN_CLANGD_ADD_STD_CPP14;
56+
}
57+
else {
58+
cppVersion = consts.NATIVE_NON_WIN_CLANGD_ADD_STD_CPP14;
59+
}
60+
}
61+
62+
addToClangdAdd(clangdExtYamlFiles, cppVersion);
2763

2864
return false;
2965
}
3066

3167

32-
export function addPlatformSpecificChanges(uePlatform: UnrealPlatform, clangdExtYamlFiles: ExtensionYamlFiles) {
68+
export function addPlatformSpecificChanges( intellisenseType: ExtensionIntellisenseType, uePlatform: UnrealPlatform, clangdExtYamlFiles: ExtensionYamlFiles, clangUri?: vscode.Uri) {
3369

3470
switch (uePlatform) {
3571
case "Win64":
36-
72+
if(intellisenseType === "Native"){
73+
for (const warning of consts.WIN_COMPILER_FLAGS_TO_ADD) {
74+
addToClangdAdd(clangdExtYamlFiles, warning);
75+
}
76+
}
3777
break;
3878
case 'Mac':
39-
79+
// TODO We use linux flags until we can get more info...
80+
if(intellisenseType === "Native"){
81+
for (const warning of consts.LINUX_COMPILER_FLAGS_TO_ADD) {
82+
addToClangdAdd(clangdExtYamlFiles, warning);
83+
}
84+
}
4085
break;
4186
case 'Linux':
42-
addToClangdAdd(clangdExtYamlFiles, consts.LINUX_CLANGD_CFG_ADD_USR_INCLUDE);
87+
if(intellisenseType === "Native"){
88+
addToClangdAdd(clangdExtYamlFiles, consts.LINUX_SYS_INCLUDE_CPP_V1);
89+
90+
for (const warning of consts.LINUX_COMPILER_FLAGS_TO_ADD) {
91+
addToClangdAdd(clangdExtYamlFiles, warning);
92+
}
93+
}
94+
else {
95+
addToClangdAdd(clangdExtYamlFiles, consts.LINUX_CLANGD_CFG_ADD_USR_INCLUDE);
96+
}
97+
4398
break;
4499
default:
45100
break;
@@ -52,15 +107,32 @@ function addToClangdAdd(clangdExtYamlFiles: ExtensionYamlFiles, addition: string
52107
if(clangdExtYamlFiles.clangd[0]){
53108
const clangdCfg: ClangdCfgFileSettings = clangdExtYamlFiles.clangd[0].docObjects[0] as ClangdCfgFileSettings;
54109
if(clangdCfg){
55-
clangdCfg.CompileFlags.Add.push(addition);
110+
if(!clangdCfg.CompileFlags.Add){
111+
clangdCfg.CompileFlags.Add = [ addition ];
112+
}
113+
else {
114+
clangdCfg.CompileFlags.Add.push(addition);
115+
}
56116
}
57117
}
58118
}
59119

60-
export function addSettingsToClangdCfg(mainWorkspace: vscode.WorkspaceFolder, defaultClangdCfgSettings: ClangdCfgFileSettings, ccPath: string) {
61-
62-
defaultClangdCfgSettings.CompileFlags.CompilationDatabase = ccPath.replaceAll("\\", '/'); // Only foward slashes allowed
120+
function addToClangdRemove(clangdExtYamlFiles: ExtensionYamlFiles, flagToRemove: string) {
121+
if(clangdExtYamlFiles.clangd[0]){
122+
const clangdCfg: ClangdCfgFileSettings = clangdExtYamlFiles.clangd[0].docObjects[0] as ClangdCfgFileSettings;
123+
if(clangdCfg){
124+
if(!clangdCfg.CompileFlags.Remove){
125+
clangdCfg.CompileFlags.Remove = [ flagToRemove ];
126+
}
127+
else {
128+
clangdCfg.CompileFlags.Remove.push(flagToRemove);
129+
}
130+
}
131+
}
132+
}
63133

134+
export function addSettingsToClangdCfg(mainWorkspace: vscode.WorkspaceFolder, defaultClangdCfgSettings: ClangdCfgFileSettings) {
135+
64136
const unrealClangdCfg = vscode.workspace.getConfiguration(consts.CONFIG_SECTION_UNREAL_CLANGD, mainWorkspace);
65137
const compilerPath = unrealClangdCfg.get<string>(consts.settingNames.unrealClangd.settings["creation.compilerPath"]);
66138

0 commit comments

Comments
 (0)