Skip to content

Commit 83daf75

Browse files
authored
Merge pull request #44 from MetabobProject/fix/highlight-processing
fix/highlight processing
2 parents 6ba9a29 + 1be9db5 commit 83daf75

File tree

5 files changed

+13
-16
lines changed

5 files changed

+13
-16
lines changed

ext-src/commands/AnalyzeDocument.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ export function activateAnalyzeCommand(context: vscode.ExtensionContext, _debug?
2121

2222
// If the user has not opened any file then we can't perform any analysis.
2323
if (!editor) {
24-
vscode.window.showErrorMessage(CONSTANTS.editorNotSelectorError);
2524
extensionEventEmitter.fire({
2625
type: 'Analysis_Error',
2726
data: 'Editor is undefined',
2827
});
2928
throw new Error('activateAnalyzeCommand: Editor is undefined');
3029
}
3130

31+
_debug?.appendLine('AnalyzeDocument.ts: activateAnalyzeCommand: editor.document: ' + JSON.stringify(editor.document));
3232
// If the user has not opened valid document i.e settings page or any other page
3333
// that is not a code file we will throw an error.
3434
if (!Util.isValidDocument(editor.document)) {
@@ -41,6 +41,7 @@ export function activateAnalyzeCommand(context: vscode.ExtensionContext, _debug?
4141
throw new Error('activateAnalyzeCommand: Selected Document is not valid');
4242
}
4343

44+
_debug?.appendLine('AnalyzeDocument.ts: activateAnalyzeCommand: Session Token: ' + sessionToken);
4445
// If the user session is not available then we can't request file analysis.
4546
if (!sessionToken) {
4647
vscode.window.showErrorMessage(CONSTANTS.sessionTokenUndefined);
@@ -52,6 +53,7 @@ export function activateAnalyzeCommand(context: vscode.ExtensionContext, _debug?
5253
}
5354

5455
const documentMetaData = Util.extractMetaDataFromDocument(editor.document);
56+
_debug?.appendLine('AnalyzeDocument.ts: activateAnalyzeCommand: documentMetaData: ' + JSON.stringify(documentMetaData));
5557

5658
Util.withProgress<SubmitRepresentationResponse>(
5759
handleDocumentAnalyze(documentMetaData, sessionToken, analyzeState, context, undefined, true, _debug),

ext-src/helpers/HandleDocumentAnalyze.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export const handleDocumentAnalyze = async (
181181
results[key] = { ...analyzeMetaData };
182182
});
183183

184+
_debug?.appendLine('AnalyzeDocument.ts: Document File name' + documentMetaData.fileName);
184185
const problems = Util.getCurrentEditorProblems(results, documentMetaData.fileName);
185186
_debug?.appendLine('AnalyzeDocument.ts: handleDocumentAnalyze: problems: ' + JSON.stringify(problems));
186187
if (!problems) {
@@ -199,9 +200,9 @@ export const handleDocumentAnalyze = async (
199200
return failedResponseReturn;
200201
}
201202

202-
const path = problems.map(item => item.path);
203+
const paths = problems.map(item => item.path);
203204

204-
const isUserOnValidEditor = path.includes(documentMetaData.fileName);
205+
const isUserOnValidEditor = paths.includes(documentMetaData.fileName);
205206
_debug?.appendLine('AnalyzeDocument.ts: handleDocumentAnalyze: isUserOnValidEditor: ' + isUserOnValidEditor);
206207
if (isUserOnValidEditor) {
207208
Util.decorateCurrentEditorWithHighlights(problems, documentMetaData.editor, _debug);

ext-src/providers/recommendation.provider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from 'vscode';
1919
import { Configuration, CreateChatCompletionRequest, OpenAIApi } from 'openai';
2020
import { explainService, ExplainProblemPayload, SuggestRecomendationPayload } from '../services';
21-
import { CurrentQuestion, CurrentQuestionState, Session, Analyze, AnalyseMetaData } from '../state';
21+
import { CurrentQuestion, CurrentQuestionState, Session, Analyze } from '../state';
2222
import { BackendService, GetChatGPTToken } from '../config';
2323
import { DiscardCommandHandler, EndorseCommandHandler } from '../commands';
2424
import CONSTANTS from '../constants';

ext-src/utils.ts

+5-11
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ export default class Utils {
7070
if (path === undefined) {
7171
return undefined
7272
}
73-
74-
const splitPath: string | undefined = path.split('/').pop()?.replace('.git', '');
73+
const splitPath: string | undefined = path.split(/\/|\\/g).pop()?.replace('.git', '');
7574

7675
if (splitPath === undefined) {
7776
return undefined
@@ -80,17 +79,11 @@ export default class Utils {
8079
return splitPath
8180
}
8281

83-
static getResource(rel: string): string {
84-
return path
85-
.resolve(this.context.extensionPath, rel.replace(/\//g, path.sep))
86-
.replace(/\\/g, '/');
87-
}
88-
8982
static extractMetaDataFromDocument(document: vscode.TextDocument): IDocumentMetaData {
90-
const filePath = document.uri.path;
83+
const filePath = document.uri.fsPath;
9184
const workspaceFolder = workspace.getWorkspaceFolder(document.uri);
92-
const relativePath = workspaceFolder ? path.relative(workspaceFolder.uri.path, filePath) : '';
93-
const splitKey: string | undefined = relativePath.split('/').pop();
85+
const relativePath = workspaceFolder ? path.relative(workspaceFolder.uri.fsPath, filePath) : '';
86+
const splitKey: string | undefined = relativePath.split(/\/|\\/g).pop();
9487
const fileContent = document.getText();
9588
const isTextDocument = Utils.isTextDocument(document);
9689
const languageId = document.languageId;
@@ -200,6 +193,7 @@ export default class Utils {
200193
const currentEditor = vscode.window.activeTextEditor;
201194
if (!currentEditor) return false;
202195

196+
_debug?.appendLine('problem file <> Editor file: ' + problemEditor.document.fileName + ' <> ' + currentEditor.document.fileName);
203197
const isUserOnProblemEditor = problemEditor.document.fileName === currentEditor.document.fileName
204198

205199
if (!isUserOnProblemEditor) return false;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "metabob",
33
"displayName": "Metabob: Debug and Refactor with AI",
44
"description": "Generative AI to automate debugging and refactoring Python code",
5-
"version": "1.2.2",
5+
"version": "1.2.5",
66
"icon": "media/extension-icon.png",
77
"repository": {
88
"url": "https://github.com/MetabobProject/metabob-vscode",

0 commit comments

Comments
 (0)