Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion vscode-extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Change Log

## [1.0.18]
- Files now always open in non-preview mode

- Files now always open in non-preview mode
23 changes: 22 additions & 1 deletion vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,28 @@
"vscode-jetbrains-sync.port": {
"type": "number",
"default": 3000,
"description": "Port number for the WebSocket server"
"description": "Port number for the WebSocket server",
"scope": "window"
},
"vscode-jetbrains-sync.pathMapping.enabled": {
"type": "boolean",
"default": false,
"description": "Enable path mapping for incoming commands from JetBrains IDE",
"scope": "window"
},
"vscode-jetbrains-sync.pathMapping.sourcePattern": {
"type": "string",
"default": "",
"description": "Source path pattern (regex) to match in incoming file paths",
"scope": "window",
"markdownDescription": "**Source path pattern (regex)**: Regular expression to match paths from JetBrains IDE. Example: `^I:[/\\\\]_SendAPI[/\\\\]sendapi-projects-root-v01`"
},
"vscode-jetbrains-sync.pathMapping.targetPath": {
"type": "string",
"default": "",
"description": "Target path to replace the matched source pattern",
"scope": "window",

Copilot AI Sep 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's trailing whitespace after the comma on this line. Remove the extra space for consistency.

Suggested change
"scope": "window",
"scope": "window",

Copilot uses AI. Check for mistakes.
"markdownDescription": "**Target path**: Path to replace the matched pattern. Example: `/workspace`"
}
}
}
Expand Down
44 changes: 42 additions & 2 deletions vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,41 @@ export class VSCodeJetBrainsSync {
this.statusBarItem.tooltip = `${this.isConnected ? 'Connected to JetBrains IDE\n' : 'Waiting for JetBrains IDE connection\n'}Click to turn sync ${this.autoReconnect ? 'off' : 'on'}`;
}

private transformIncomingFilePath(originalPath: string): string {
const config = vscode.workspace.getConfiguration('vscode-jetbrains-sync');
const pathMappingEnabled = config.get<boolean>('pathMapping.enabled', false);

if (!pathMappingEnabled) {
return originalPath;
}

const sourcePattern = config.get<string>('pathMapping.sourcePattern', '');
const targetPath = config.get<string>('pathMapping.targetPath', '');

if (!sourcePattern || !targetPath) {
const missing = [];
if (!sourcePattern) missing.push('sourcePattern');
if (!targetPath) missing.push('targetPath');
console.log(`Path mapping enabled but the following configuration value(s) are empty: ${missing.join(', ')}`);
return originalPath;
}

try {
const regex = new RegExp(sourcePattern, 'g');

Copilot AI Sep 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the global flag 'g' with replace() can cause unexpected behavior when the same RegExp object is reused, as it maintains state between calls. Consider removing the 'g' flag since replace() will replace all occurrences by default when using a string replacement.

Suggested change
const regex = new RegExp(sourcePattern, 'g');
const regex = new RegExp(sourcePattern);

Copilot uses AI. Check for mistakes.
const transformedPath = originalPath.replace(regex, targetPath);

if (transformedPath !== originalPath) {
console.log(`Path transformed: ${originalPath} -> ${transformedPath}`);
}

return transformedPath;
} catch (error) {
console.error('Error in path transformation:', error);
console.log(`Invalid regex pattern: ${sourcePattern}`);
return originalPath;
}
}

public toggleAutoReconnect() {
this.autoReconnect = !this.autoReconnect;

Expand Down Expand Up @@ -204,9 +239,14 @@ export class VSCodeJetBrainsSync {
return;
}

// Transform the file path using path mapping once at the beginning
const transformedPath = this.transformIncomingFilePath(state.filePath);

try {
this.isHandlingExternalUpdate = true;
const uri = vscode.Uri.file(state.filePath);

const uri = vscode.Uri.file(transformedPath);

const document = await vscode.workspace.openTextDocument(uri);
const editor = await vscode.window.showTextDocument(document, {preview: false});

Expand All @@ -219,7 +259,7 @@ export class VSCodeJetBrainsSync {
);
} catch (error) {
console.error('Error handling incoming state:', error);
vscode.window.showErrorMessage(`Failed to open file: ${state.filePath}`);
vscode.window.showErrorMessage(`Failed to open file: ${transformedPath}`);
} finally {
this.isHandlingExternalUpdate = false;
}
Expand Down