Skip to content

Commit

Permalink
Merge branch '94Bo-v2' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
boocs committed Jul 23, 2024
2 parents 1fd51aa + 76d7ffe commit 50d016b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 31 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

- Create command that shows clang and clangd version in terminal

## [2.5.1] 2024-07-22
### Added from user 94Bo
- Linux and Mac users will use RunUBT.sh instead of calling UBT directly if available
- When choosing a compile commands entry for completionHelper.cpp, filter out non main source folders
### Added
- Windows will use RunUBT.bat if available
### Removed
- removed -vscode flag when calling UBT (it gets ignored anyway)
### Fixed
- npm audit fix

## [2.5.0] 2024-05-05
### Changed
- Moved to using a project's Native Intellisense files instead of using UBT's mode=GenerateClangDataBase
Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion 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.5.0",
"version": "2.5.1",
"engines": {
"vscode": "^1.77.3"
},
Expand Down
38 changes: 26 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export async function activate(context: vscode.ExtensionContext) {

args = [
"-projectfiles",
"-vscode",
`-project=${uprojectUri.fsPath}`,
"-game",
"-engine",
Expand Down Expand Up @@ -992,6 +991,21 @@ async function getUbtPath(ueUri: vscode.Uri | undefined) {
console.error(tr.URI_SEND_TO_GETUBTPATH_WAS_UNDEFINED);
return null;
}

const unixUBTWrapperScripUri = vscode.Uri.joinPath(ueUri, ...consts.END_UBT_SCRIPT_FILE_NAMES_UNIX);
if(process.platform.toLocaleLowerCase() !== "win32" && await doesUriExist(unixUBTWrapperScripUri)) {
// We are in Unix, so call wrapper script of UBT to use dotnet from Unreal Engine.
// That's 'RunUBT.sh'.
return unixUBTWrapperScripUri.fsPath;
}

const winUBTWrapperScripUri = vscode.Uri.joinPath(ueUri, ...consts.END_UBT_SCRIPT_FILE_NAMES_WIN);
if(process.platform === "win32" && await doesUriExist(winUBTWrapperScripUri)) {
// We are in Windows, so call wrapper script of UBT to use dotnet from Unreal Engine.
// That's 'RunUBT.bat'.
return winUBTWrapperScripUri.fsPath;
}

const ubtDirUri = vscode.Uri.joinPath(ueUri, ...consts.END_DIRECTORY_NAMES_TO_UNREAL_BUILD_TOOL);

if (!(await doesUriExist(ubtDirUri))) {
Expand Down Expand Up @@ -1906,19 +1920,13 @@ async function handleCompletionHelper() {
return;
}

const ccFileString = await getFileString(compileCommandsUri);
if(!ccFileString){
return;
}

const responsePaths = await getUniqueResponseFilePathsFromCompileCommands(ccFileString);
// Since we only intrested in the main source folder later, we should filter only the main source file.
const responsePaths = await getUniqueResponseFilePathsFromCompileCommandsWithFilter(ccFile, mainSourceFolderPathLower);
if(!responsePaths){
return;
}

let responsePathMostEntries;

responsePathMostEntries = Object.keys(responsePaths).reduce((previous, current, i, pathsArray) => {

let responsePathMostEntries = Object.keys(responsePaths).reduce((previous, current, i, pathsArray) => {
return responsePaths[current] > responsePaths[previous] ? current : previous;
});

Expand Down Expand Up @@ -2679,8 +2687,14 @@ async function convertFilePathsToUris(paths: Iterable<string>) {
return rspUris;
}

function getUniqueResponseFilePathsFromCompileCommandsWithFilter(ccFile: typ.CompileCommandFile, filterFilePathPrefix?: string): Promise<Record<string, number> | undefined> {
return getUniqueResponseFilePathsFromCompileCommands(JSON.stringify(filterFilePathPrefix ?
ccFile.filter(ccFile => ccFile.file.toLowerCase().startsWith(filterFilePathPrefix))
: ccFile
));
}

async function getUniqueResponseFilePathsFromCompileCommands(ccFileString: string): Promise<Record<string, number> | undefined> {

const reResponseFlag = new RegExp(consts.REGEX_RESPONSE_COMPILER_FLAG, "gm");
const rspPathStrings = ccFileString.matchAll(reResponseFlag);

Expand Down
12 changes: 10 additions & 2 deletions src/libs/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AllDefaultSettings, AllSettingNames, CCppDefaultSettings, CCppSettingNa
import type { ClangdCfgFileSettings, CompileFlags, ClangArgWithValue, GlobPatterns, BackupGlobDirectories } from "./types";
import type { Overwrite } from './indexTypes';

export const EXTENSION_VERSION = "2.5.0";
export const EXTENSION_VERSION = "2.5.1";
export const VALIDATE_UNREAL_VERSIONS: { min: ueHelpers.UnrealVersion, max: ueHelpers.UnrealVersion } =
{ min: { major: 5, minor: 2, patch: 0 }, max: { major: 6, minor: 0, patch: 0 } }; // The unreal versions this extension was created for

Expand Down Expand Up @@ -55,7 +55,7 @@ export const NATIVE_NON_WIN_CLANGD_ADD_STD_CPP14 = "-std=c++14";

export const FOLDER_NATIVE_COMPILE_COMMANDS_DEFAULT_FOLDER_NAME = "compileCommands_Default";

export const REGEX_RESPONSE_COMPILER_FLAG = "(?<=@).*.rsp";
export const REGEX_RESPONSE_COMPILER_FLAG = "(?<=[\"']@).*?\\.rsp(?=\"|')";

export const NATIVE_CODE_WORKSPACE_BACKUP_SETTINGS = [
"clangd.arguments", "clangd.path", "clangd.detectExtensionConflicts", "files.associations", "workbench.colorCustomizations", "editor.suggestFontSize", "dotnet.defaultSolution"
Expand Down Expand Up @@ -280,6 +280,14 @@ export const UPDATE_COMPILE_COMMANDS_PROJECT_NAME_EDITOR_SUFFIX = "Editor";
export const END_DIRECTORY_NAMES_TO_UNREAL_BUILD_TOOL = [
"Engine", "Binaries", "DotNET", "UnrealBuildTool"
];
export const END_UBT_SCRIPT_FILE_NAMES_UNIX = [
"Engine", "Build", "BatchFiles", "RunUBT.sh"
];

export const END_UBT_SCRIPT_FILE_NAMES_WIN = [
"Engine", "Build", "BatchFiles", "RunUBT.bat"
];


export const CREATION_ARG_SETTING_UNREAL_PLATFORM = "platform";
export const CREATION_ARG_SETTING_OVERWRITE = "overwrite";
Expand Down

0 comments on commit 50d016b

Please sign in to comment.