Skip to content

Commit

Permalink
2.5.0 Native Intellisense
Browse files Browse the repository at this point in the history
  • Loading branch information
boocs committed May 9, 2024
1 parent 1814677 commit 1fd51aa
Show file tree
Hide file tree
Showing 11 changed files with 1,388 additions and 327 deletions.
9 changes: 8 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": [
"@typescript-eslint"
],
"extends": [
//"eslint:recommended",
//"plugin:@typescript-eslint/recommended"
//"plugin:@typescript-eslint/recommended-requiring-type-checking"
],
"rules": {
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/semi": "warn",
//"@typescript-eslint/await-thenable": "error",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@

- Create command that shows clang and clangd version in terminal

## [2.5.0] 2024-05-05
### Changed
- Moved to using a project's Native Intellisense files instead of using UBT's mode=GenerateClangDataBase
- mode=GenerateClangDataBase was overwriting build files causing you to have to rebuild
- In .clangd, CompilationDatabase is now a relative path(set during creation process)
### Added
- Native - Removed PCH header from Intellisense files. Not needed and increases intellisense loading greatly.
- Native - Setting: unreal-clangd.IntellisenseType. This is always set to 'Native' even if switched.
- Native - Setting: unreal-clangd.native.minutesTillIntellisenseFilesAreOld
- 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.
- Native - Setting: unreal-clangd.native.code-workspaceFileBackupSettings
- 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.
### Removed
- -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.
### Fixed
- Code that added compiler flags to eventually go in .clangd

## [2.3.0] 2024-01-21
### Added
- clang-format: added "NamespaceIndentation: All" to default config when created
Expand Down
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
```

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

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

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

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

For `Unreal 5.2` you want to enable `v14.34`:
* For `Unreal 5.2` you want to enable `v14.34`:

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

For `Unreal 5.3` you want to enable `v14.36`:
* For `Unreal 5.3` you want to enable `v14.36`:

![image](https://github.com/boocs/unreal-clangd/assets/62588629/aec88536-557e-4171-96c3-c73d8dc15766)
![image](https://github.com/boocs/unreal-clangd/assets/62588629/aec88536-557e-4171-96c3-c73d8dc15766)

* For `Unreal 5.4` you want to enable `v14.38`
- (Pic not shown)

4. If you haven't created your Unreal project yet you can skip steps 5/6
5. For existing Unreal projects, first Refresh your project (this will overwrite your workspace file which we fix in step 6)
Expand Down Expand Up @@ -362,7 +365,7 @@ The other reason was a Unreal design change. 5.0.0 uses compile commands while 5
* `unreal-clangd.createUnrealClangdProject`: Creates all files and settings for clangd to work with an Unreal project
* `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)**
* `unreal-clangd.uninstall`: Uninstalls Unreal-clangd files and settings **(It will prompt you before deletion)**
* `unreal-clangd.fixQuotesResponseFiles`: Runs the quote fix for paths in response files **(Will auto run if setting is true)**
* `unreal-clangd.fixIntellisenseFiles`: Runs the quote fix for paths in response files **(Will auto run if setting is true)**
* `unreal-clangd.tidyNoLintCurrentLine`: Removes clang Tidy linting on current line
- **Modifies code**
- **Also found in context menu**
Expand All @@ -377,6 +380,13 @@ The other reason was a Unreal design change. 5.0.0 uses compile commands while 5
```

### Settings

* `unreal-clangd.IntellisenseType`: This is always set to 'Native' even if switched (for now)
#### Native
* `unreal-clangd.native.minutesTillIntellisenseFilesAreOld`:
- 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.
* `unreal-clangd.native.code-workspaceFileBackupSettings`:
- 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.
#### Compile Commands
* `unreal-clangd.compileCommands.execType`: Task | Debug
- **Debug requires Microsoft C# extension which lets you see UBT logs**
Expand All @@ -399,7 +409,7 @@ The other reason was a Unreal design change. 5.0.0 uses compile commands while 5
- Also activates when copying and pasting a function

#### Fixes
* `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)**
* `unreal-clangd.fixes.intellisenseFiles`: Enables/disables Change or fix intellisense files when needed. **(This will auto fix whenever it detects compile command changes)**
* `unreal-clangd.fixes.delegateFunctionCompletions`: Some delegate functions completions aren't correct because of macro expansion. This will fix the completion when detected.
- See [this](#delegate-function-name-completions) section for more info
* `unreal-clangd.fixes.focusSuggestionDelay`: Fixes code completion selection not happening with parameter hints. Default 350 [see section](#function-parameter-completions)
Expand Down Expand Up @@ -555,14 +565,15 @@ Click the console 'OUTPUT' tab and change the top right drop down to 'unreal cla
* ![](https://user-images.githubusercontent.com/62588629/233814109-2ff37ccf-faaa-4fc0-bf77-e9e85bfa6120.png)
```
```
### Clangd Project Files
### **.clangd file**
Lets you Add/Remove Intellisense compile flags that clang uses, among other things. See [clangd docs.](https://clangd.llvm.org/config)
**note:** A lot of functionality was added with clangd-14 so won't work wth earlier versions
```
```
### **.clang-format file**
The clangd extension will take over formatting of your C++ documents.
Expand All @@ -575,8 +586,7 @@ This extension creates a bare minimum format file that makes code look pretty go
For more format settings info: https://clang.llvm.org/docs/ClangFormatStyleOptions.html
```
```
### **.clang-tidy file**
Used for the C++ linter. You can see the docs [here](https://clang.llvm.org/extra/clang-tidy/)
Expand Down Expand Up @@ -609,6 +619,7 @@ The file is located in your project's parent folder.
`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.
```
```
Expand Down Expand Up @@ -793,9 +804,7 @@ Thanks to Mark at [stackoverflow](https://stackoverflow.com/a/76096050/13950944)
```
### Linux Fixes
Simple fix is to include /usr/include using -isystem
- This is `automatically fixed` in the .clangd file that is created for your project.
Check the .clangd project file 'Add' section for all the fixes applied.
```
```
Expand Down Expand Up @@ -1225,17 +1234,8 @@ https://github.com/electron/electron/issues/32857
```
```
### Installing Microsoft C++ Extension After Install
It's faster not to recreate a project of this extension, with the 'lazy' setting, and just set the correct settings manually.
1. Go to your project's .vscode directory
2. Open settings.json
3. Paste these settings in:
```
"C_Cpp.autocomplete": "disabled",
"C_Cpp.errorSquiggles": "disabled",
"C_Cpp.formatting": "disabled",
"C_Cpp.intelliSenseEngine": "disabled"
```
The extension `now detects` that the Microsoft C++ extension is installed and will auto set correct settings on startup or reload.
```
```
Expand Down
40 changes: 34 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "unreal-clangd",
"displayName": "Unreal Clangd",
"description": "clangd helper for UE 5.2+",
"version": "2.3.0",
"version": "2.5.0",
"engines": {
"vscode": "^1.77.3"
},
Expand Down Expand Up @@ -37,9 +37,8 @@
"category": "unreal clangd"
},
{
"command": "unreal-clangd.fixQuotesResponseFiles",
"title": "Fix paths in response files by surrounding them with quotes",
"shortTitle": "Fix paths in response files",
"command": "unreal-clangd.fixIntellisenseFiles",
"title": "Fix quotes in gcd(Intellisense) files.",
"category": "unreal clangd"
},
{
Expand Down Expand Up @@ -72,10 +71,39 @@
{
"title": "Unreal Clangd",
"properties": {
"unreal-clangd.fixes.responseFilesQuotedPaths": {
"unreal-clangd.IntellisenseType": {
"type": "string",
"default": "Native",
"readOnly": true,
"enum": [
"Native",
"GenerateClangDataBase"
],
"markdownEnumDescriptions": [
"Uses your project's native Intellisense files",
"Uses GenerateClangDataBase for Intellisense `(currently unavailable)`"
],
"description": "Which Intellisense files to use for your project.",
"scope": "resource",
"order": 0
},
"unreal-clangd.native.code-workspaceFileBackupSettings": {
"type": "array",
"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!",
"scope": "resource",
"order": 1
},
"unreal-clangd.native.minutesTillIntellisenseFilesAreOld": {
"type": "number",
"default": 5,
"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.",
"scope": "resource",
"order": 1
},
"unreal-clangd.fixes.intellisenseFiles": {
"type": "boolean",
"default": true,
"description": "In reponse files, surrounds paths with quotes.",
"description": "Fixes Intellisense files when they have errors or need changes.",
"scope": "resource"
},
"unreal-clangd.fixes.delegateFuncCompletions": {
Expand Down
92 changes: 82 additions & 10 deletions src/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import * as vscode from "vscode";
import * as consts from "./libs/consts";

import { UnrealPlatform } from "./libs/indexTypes";
import { AllDefaultSettings, ClangdCfgFileSettings, ExtensionYamlFiles } from "./libs/types";
import { AllDefaultSettings, ClangdCfgFileSettings, ExtensionYamlFiles, ExtensionIntellisenseType} from "./libs/types";
import { UnrealVersion } from "./libs/ueHelpers";


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

if (!clangdPath) {
console.error("No clangd paths found!");
Expand All @@ -24,22 +25,76 @@ export function addDynamicDefaultSettingsToConfig(mainWorkspace: vscode.Workspac
console.error("Couldn't get clangd settings path.");
return true;
}

if(!ueVersion){
console.error("Couldn't get UE version!");
return true;
}

let cppVersion = "";

if(process.platform === "win32") {
cppVersion = consts.NATIVE_WIN_CLANGD_ADD_STD_CPP20;
}
else {
cppVersion = consts.NATIVE_NON_WIN_CLANGD_ADD_STD_CPP20;
}


if(ueVersion.major === 5 && ueVersion.minor < 2){
if(process.platform === "win32") {
cppVersion = consts.NATIVE_WIN_CLANGD_ADD_STD_CPP17;
}
else {
cppVersion = consts.NATIVE_NON_WIN_CLANGD_ADD_STD_CPP17;
}
}

if(ueVersion.major === 4){
if(process.platform === "win32") {
cppVersion = consts.NATIVE_WIN_CLANGD_ADD_STD_CPP14;
}
else {
cppVersion = consts.NATIVE_NON_WIN_CLANGD_ADD_STD_CPP14;
}
}

addToClangdAdd(clangdExtYamlFiles, cppVersion);

return false;
}


export function addPlatformSpecificChanges(uePlatform: UnrealPlatform, clangdExtYamlFiles: ExtensionYamlFiles) {
export function addPlatformSpecificChanges( intellisenseType: ExtensionIntellisenseType, uePlatform: UnrealPlatform, clangdExtYamlFiles: ExtensionYamlFiles, clangUri?: vscode.Uri) {

switch (uePlatform) {
case "Win64":

if(intellisenseType === "Native"){
for (const warning of consts.WIN_COMPILER_FLAGS_TO_ADD) {
addToClangdAdd(clangdExtYamlFiles, warning);
}
}
break;
case 'Mac':

// TODO We use linux flags until we can get more info...
if(intellisenseType === "Native"){
for (const warning of consts.LINUX_COMPILER_FLAGS_TO_ADD) {
addToClangdAdd(clangdExtYamlFiles, warning);
}
}
break;
case 'Linux':
addToClangdAdd(clangdExtYamlFiles, consts.LINUX_CLANGD_CFG_ADD_USR_INCLUDE);
if(intellisenseType === "Native"){
addToClangdAdd(clangdExtYamlFiles, consts.LINUX_SYS_INCLUDE_CPP_V1);

for (const warning of consts.LINUX_COMPILER_FLAGS_TO_ADD) {
addToClangdAdd(clangdExtYamlFiles, warning);
}
}
else {
addToClangdAdd(clangdExtYamlFiles, consts.LINUX_CLANGD_CFG_ADD_USR_INCLUDE);
}

break;
default:
break;
Expand All @@ -52,15 +107,32 @@ function addToClangdAdd(clangdExtYamlFiles: ExtensionYamlFiles, addition: string
if(clangdExtYamlFiles.clangd[0]){
const clangdCfg: ClangdCfgFileSettings = clangdExtYamlFiles.clangd[0].docObjects[0] as ClangdCfgFileSettings;
if(clangdCfg){
clangdCfg.CompileFlags.Add.push(addition);
if(!clangdCfg.CompileFlags.Add){
clangdCfg.CompileFlags.Add = [ addition ];
}
else {
clangdCfg.CompileFlags.Add.push(addition);
}
}
}
}

export function addSettingsToClangdCfg(mainWorkspace: vscode.WorkspaceFolder, defaultClangdCfgSettings: ClangdCfgFileSettings, ccPath: string) {

defaultClangdCfgSettings.CompileFlags.CompilationDatabase = ccPath.replaceAll("\\", '/'); // Only foward slashes allowed
function addToClangdRemove(clangdExtYamlFiles: ExtensionYamlFiles, flagToRemove: string) {
if(clangdExtYamlFiles.clangd[0]){
const clangdCfg: ClangdCfgFileSettings = clangdExtYamlFiles.clangd[0].docObjects[0] as ClangdCfgFileSettings;
if(clangdCfg){
if(!clangdCfg.CompileFlags.Remove){
clangdCfg.CompileFlags.Remove = [ flagToRemove ];
}
else {
clangdCfg.CompileFlags.Remove.push(flagToRemove);
}
}
}
}

export function addSettingsToClangdCfg(mainWorkspace: vscode.WorkspaceFolder, defaultClangdCfgSettings: ClangdCfgFileSettings) {

const unrealClangdCfg = vscode.workspace.getConfiguration(consts.CONFIG_SECTION_UNREAL_CLANGD, mainWorkspace);
const compilerPath = unrealClangdCfg.get<string>(consts.settingNames.unrealClangd.settings["creation.compilerPath"]);

Expand Down
Loading

0 comments on commit 1fd51aa

Please sign in to comment.