Skip to content

Data Explorer: Preserve non-file URIs when creating DuckDB clients #7533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { PositronDataExplorerEditorInput } from './positronDataExplorerEditorInp
import { POSITRON_DATA_EXPLORER_IS_ACTIVE_EDITOR, POSITRON_DATA_EXPLORER_IS_COLUMN_SORTING, POSITRON_DATA_EXPLORER_IS_PLAINTEXT, POSITRON_DATA_EXPLORER_LAYOUT } from './positronDataExplorerContextKeys.js';
import { Codicon } from '../../../../base/common/codicons.js';
import { PositronDataExplorerUri } from '../../../services/positronDataExplorer/common/positronDataExplorerUri.js';
import { URI } from '../../../../base/common/uri.js';
import { EditorOpenSource } from '../../../../platform/editor/common/editor.js';
import { IPathService } from '../../../services/path/common/pathService.js';
import { toLocalResource } from '../../../../base/common/resources.js';
Expand Down Expand Up @@ -750,22 +749,24 @@ class PositronDataExplorerOpenAsPlaintextAction extends Action2 {
return;
}

// Parse this URI - gives underlying FS URI if not memory-backed (scheme = duckdb)
const parsedDataExplorerURI = PositronDataExplorerUri.parse(originalURI);
if (!parsedDataExplorerURI) {
let backingUri = PositronDataExplorerUri.backingUri(originalURI);
if (!backingUri) {
return;
}

// Convert raw duckdb URI to appropriate file URI (scheme = file if local, vscode-remote if server)
const localURI = toLocalResource(
URI.parse(parsedDataExplorerURI),
environmentService.remoteAuthority,
pathService.defaultUriScheme
);
// Convert file URIs to the "local" scheme, i.e. vscode-remote when
// running as a server.
if (backingUri.scheme === 'file') {
backingUri = toLocalResource(
backingUri,
environmentService.remoteAuthority,
pathService.defaultUriScheme
);
}

// Invoke editor for file, using default editor (text) association
await editorService.openEditor({
resource: localURI,
resource: backingUri,
options: {
override: DEFAULT_EDITOR_ASSOCIATION.id,
source: EditorOpenSource.USER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class PositronDataExplorerContribution extends Disposable {

// We create a data explorer URI that will use the DuckDB client
// that we just created.
const newResource = PositronDataExplorerUri.generate(`duckdb:${resource.path}`);
const newResource = PositronDataExplorerUri.generate(`duckdb:${resource.toString()}`);
return createDataExplorerEditor({
resource: newResource,
options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import { IPositronDataExplorerService, PositronDataExplorerLayout } from '../../
import { PositronDataExplorerEditorInput } from './positronDataExplorerEditorInput.js';
import { PositronDataExplorerClosed, PositronDataExplorerClosedStatus } from '../../../browser/positronDataExplorer/components/dataExplorerClosed/positronDataExplorerClosed.js';
import { POSITRON_DATA_EXPLORER_IS_COLUMN_SORTING, POSITRON_DATA_EXPLORER_IS_PLAINTEXT, POSITRON_DATA_EXPLORER_LAYOUT } from './positronDataExplorerContextKeys.js';
import { URI } from '../../../../base/common/uri.js';

/**
* IPositronDataExplorerEditorOptions interface.
Expand Down Expand Up @@ -362,8 +361,8 @@ export class PositronDataExplorerEditor extends EditorPane implements IPositronD
positronDataExplorerInstance.tableDataDataGridInstance.isColumnSorting
);

const uri = URI.parse(this._identifier);
if (uri.scheme === 'duckdb') {
const uri = PositronDataExplorerUri.backingUri(input.resource);
if (uri) {
this._isPlaintextContextKey.set(PLAINTEXT_EXTS.some(ext => uri.path.endsWith(ext)));
} else {
this._isPlaintextContextKey.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class PositronDataExplorerDuckDBBackend extends Disposable implements IDa
private readonly uri: URI
) {
super();
this.clientId = `duckdb:${this.uri.path}`;
this.clientId = `duckdb:${this.uri.toString()}`;
this.initialSetup = this.openDataset();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,19 @@ export class PositronDataExplorerUri {
return undefined;
}
}

/**
* Parses a Positron data explorer URI and retrieves the URI of the backing file, if any.
* @param resource The data explorer resource.
* @returns A URI for the backing file, if any.
*/
public static backingUri(resource: URI): URI | undefined {
const identifier = PositronDataExplorerUri.parse(resource);
// Runtime comm IDs have no originating URIs.
if (!identifier || !identifier.startsWith('duckdb:')) {
return undefined;
}
// This will be something like "duckdb:file:///path/to/file.csv".
return URI.parse(identifier.replace('duckdb:', ''));
}
}