diff --git a/vscode-extension/CHANGELOG.md b/vscode-extension/CHANGELOG.md index 0b9a17f..238b911 100644 --- a/vscode-extension/CHANGELOG.md +++ b/vscode-extension/CHANGELOG.md @@ -1,4 +1,5 @@ # Change Log ## [1.0.18] -- Files now always open in non-preview mode \ No newline at end of file + +- Files now always open in non-preview mode diff --git a/vscode-extension/package.json b/vscode-extension/package.json index ad7c1e7..92f12d1 100644 --- a/vscode-extension/package.json +++ b/vscode-extension/package.json @@ -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", + "markdownDescription": "**Target path**: Path to replace the matched pattern. Example: `/workspace`" } } } diff --git a/vscode-extension/src/extension.ts b/vscode-extension/src/extension.ts index 5ef8926..47ed6b7 100644 --- a/vscode-extension/src/extension.ts +++ b/vscode-extension/src/extension.ts @@ -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('pathMapping.enabled', false); + + if (!pathMappingEnabled) { + return originalPath; + } + + const sourcePattern = config.get('pathMapping.sourcePattern', ''); + const targetPath = config.get('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'); + 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; @@ -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}); @@ -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; }