Skip to content

Commit a85586f

Browse files
committed
fix/ read and write issues with relative path for project files
1 parent 078be63 commit a85586f

4 files changed

Lines changed: 13 additions & 4 deletions

File tree

‎src/extension.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,8 @@ async function runCppcheckOnFileXML(
725725
usingProjectFile = true;
726726
args.push(`--file-filter=${filePath}`);
727727
var projectFilePath = processedArgs.split('--project=')[1].split(' ')[0];
728-
projectFileStore.setUri(vscode.Uri.file(projectFilePath));
728+
const absoluteProjectFilePath = resolvePath(projectFilePath);
729+
projectFileStore.setUri(vscode.Uri.file(absoluteProjectFilePath));
729730
} else {
730731
args.push(
731732
'--suppress=unusedFunction',

‎src/util/codeActions.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
113113
/*
114114
* Actions only applicable if project file is used
115115
*/
116-
if (this.projectFileStore.hasCppcheckProjectFile()) {
116+
if (this.projectFileStore.hasCppcheckProjectFile()) {
117117
// Set up an action for suppressing warning of a given type universally
118118
const suppressTypeAction = new vscode.CodeAction(
119119
`Suppress warning type ${diagnosticCode} universally (in project file)`,

‎src/util/files.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class ProjectFileStore {
1616
if (!uri) {
1717
return false;
1818
}
19-
var projectFileType = uri.path.split('.')[1];
19+
var projectFileType = getFileType(uri.path);
2020
return projectFileType.toLowerCase() === 'cppcheck';
2121
}
2222

@@ -25,15 +25,22 @@ export class ProjectFileStore {
2525
}
2626
}
2727

28+
export function getFileType(path : string) {
29+
const splitFilePath = path.split('.');
30+
return splitFilePath[splitFilePath.length - 1];
31+
}
32+
2833
export async function writeSuppressionToProjectFile(projectFileUri : vscode.Uri, warningType : String, file? : String, symbolName? : String) : Promise<boolean> {
29-
const fileType = projectFileUri.toString().split('.')[1];
34+
const fileType = getFileType(projectFileUri.toString());
3035
if (fileType !== 'cppcheck') {
3136
throw new Error(`Function writeSuppressionToProjectFile only supports writing to .cppcheck project files! Recieved file is of type .${fileType}`);
3237
}
3338

3439
// Open project file with vscode workspace API
40+
console.log('projectFileUri', projectFileUri);
3541
const document = await vscode.workspace.openTextDocument(projectFileUri);
3642
const text = document.getText();
43+
console.log('projectFile opened');
3744
const edit = new vscode.WorkspaceEdit();
3845
var textToInsert = '';
3946
var positionToInsertAt = 0;

‎tsconfig.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"lib": [
77
"ES2022"
88
],
9+
"types": [ "mocha" ],
910
"sourceMap": true,
1011
"rootDir": "src",
1112
"strict": true, /* enable all strict type-checking options */

0 commit comments

Comments
 (0)