Skip to content

Commit

Permalink
fix: windows paths & diff application (rainbow)
Browse files Browse the repository at this point in the history
  • Loading branch information
alashchev17 committed Oct 22, 2024
1 parent d999df0 commit 3926e26
Showing 1 changed file with 12 additions and 56 deletions.
68 changes: 12 additions & 56 deletions src/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class PanelWebview implements vscode.WebviewViewProvider {
// }

getOpenFiles(): string[] {
const openDocuments = vscode.workspace.textDocuments;
const openDocuments = vscode.workspace.textDocuments.filter(doc => !doc.isClosed);
const openFiles = openDocuments.map(document => document.uri.fsPath);
return openFiles;
}
Expand Down Expand Up @@ -688,84 +688,42 @@ export class PanelWebview implements vscode.WebviewViewProvider {
global.is_chat_streaming = state;
}

removeQuestionMarks(filePath: string): string {
// Remove the sequence '\\?\\'
let cleanedPath = filePath.replace(/\\\?\\/g, '');
// Remove leading backslashes if present
cleanedPath = cleanedPath.replace(/^\\+/, '');
// Replace question marks and backslashes
// return cleanedPath.replace(/\?/g, '').replace(/\\/g, '/');
return cleanedPath;
}

private filePathToUri(fileName: string) {
// TODO: check if posix paths are sent by the lsp on a windows system
console.log(`[DEBUG]: original file_name: `, fileName);
if (fileName.startsWith('\\?\\')) {
fileName = fileName.slice(3); // Remove the '\\?\' prefix
const extendedLengthPattern = /^\\\\?\\?/i;
if (extendedLengthPattern.test(fileName)) {
fileName = fileName.slice(3); // Remove the '\\?\' or '\\\\?\\' prefix
}
const parsedPath = path.parse(fileName);
return vscode.Uri.file(path.posix.format(parsedPath));
}

async startFileAnimation(fileName: string) {

const openFiles = this.getOpenFiles();
console.log(`[COND]: openFiles: `, openFiles);
const editor = vscode.window.activeTextEditor;

const workspaceFolders = vscode.workspace.workspaceFolders;
if (!workspaceFolders) {
return;
}

const workspace_path = workspaceFolders[0].uri.fsPath;
const relative_path = path.relative(workspace_path, fileName.replace(/\?/g, ''));

const uri = this.filePathToUri(fileName);
console.log(`[COND]: obtained uri: `, {uri: uri});

console.log(`[COND]: openFiles.some(file => file.includes(relative_path): ${openFiles.some(file => file.includes(relative_path))}`);
let document: vscode.TextDocument | null = null;
if(!openFiles.some(file => file.includes(relative_path))) {
console.log(`[COND]: файла нет, но вы держитесь`);
// document = await vscode.workspace.openTextDocument(uri);
}
if (!editor) { return; }
document = await vscode.workspace.openTextDocument(uri);

const document = await vscode.workspace.openTextDocument(uri);
await vscode.window.showTextDocument(document);

const state = estate.state_of_editor(editor, "start_animate for file: " + uri);
if(!state) {return;}

await estate.switch_mode(state, estate.Mode.DiffWait);
const startPosition = new vscode.Position(0, 0);
if (!document) {return;}
const endPosition = new vscode.Position(document.lineCount - 1, document.lineAt(document.lineCount - 1).text.length);

state.showing_diff_for_range = new vscode.Range(startPosition, endPosition);
animation_start(editor, state);
}

async stopFileAnimation(fileName: string) {

const openFiles = this.getOpenFiles();
const editor = vscode.window.activeTextEditor;

const uri = this.filePathToUri(fileName);
console.log(`[DEBUG]: obtained uri: `, {uri: uri});

const workspaceFolders = vscode.workspace.workspaceFolders;
if (!workspaceFolders) {
return;
}

const workspace_path = workspaceFolders[0].uri.fsPath;
const relative_path = path.relative(workspace_path, fileName.replace(/\?/g, ''));

console.log(`[COND]: openFiles.some(file => file.includes(relative_path): ${openFiles.some(file => file.includes(relative_path))}`);
if(!openFiles.some(file => file.includes(relative_path))|| !editor) {return;}

const state = estate.state_of_editor(editor, "stop_animate for file: " + uri);
if(!state) {return;}

await estate.switch_mode(state, estate.Mode.Normal);
}

Expand Down Expand Up @@ -858,11 +816,7 @@ export class PanelWebview implements vscode.WebviewViewProvider {


async handleOpenFile(file: {file_name:string, line?: number}) {
// const normalized_path = this.removeQuestionMarks(file.file_name);

// const uri = vscode.Uri.file(normalized_path);
const uri = this.filePathToUri(file.file_name);
console.log(`[DEBUG]: obtained uri: `, {uri: uri});
const document = await vscode.workspace.openTextDocument(uri);

if(file.line !== undefined) {
Expand All @@ -873,6 +827,8 @@ export class PanelWebview implements vscode.WebviewViewProvider {
} else {
await vscode.window.showTextDocument(document);
}

return document;
}

getColorTheme(): "light" | "dark" {
Expand Down

0 comments on commit 3926e26

Please sign in to comment.