Skip to content

Commit

Permalink
Fixes opening Data Explorer as plaintext on Web & Windows (#6195)
Browse files Browse the repository at this point in the history
Prior PR #6132 adds UI affordance, but logic does not work on Web or
Windows due to path handling issues. This fixes both.
  • Loading branch information
samclark2015 authored Jan 31, 2025
1 parent 644c0e8 commit 5d85617
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ 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';
import { IWorkbenchEnvironmentService } from '../../../services/environment/common/environmentService.js';

/**
* Positron data explorer action category.
Expand Down Expand Up @@ -731,10 +734,37 @@ class PositronDataExplorerOpenAsPlaintextAction extends Action2 {
*/
async run(accessor: ServicesAccessor): Promise<void> {
// Access the services we need.
// const textEditorService = accessor.get(ITextEditorService);
const pathService = accessor.get(IPathService);
const environmentService = accessor.get(IWorkbenchEnvironmentService);
const editorService = accessor.get(IEditorService);
const dataExplorerUri = URI.parse(PositronDataExplorerUri.parse(EditorResourceAccessor.getOriginalUri(editorService.activeEditor)!)!);
await editorService.openEditor({ resource: URI.parse(dataExplorerUri.fsPath), options: { override: DEFAULT_EDITOR_ASSOCIATION.id, source: EditorOpenSource.USER } });

// Grab Data Explorer URI (scheme = positron-data-explorer)
const originalURI = EditorResourceAccessor.getOriginalUri(editorService.activeEditor);
if (!originalURI) {
return;
}

// Parse this URI - gives underlying FS URI if not memory-backed (scheme = duckdb)
const parsedDataExplorerURI = PositronDataExplorerUri.parse(originalURI);
if (!parsedDataExplorerURI) {
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
);

// Invoke editor for file, using default editor (text) association
await editorService.openEditor({
resource: localURI,
options: {
override: DEFAULT_EDITOR_ASSOCIATION.id,
source: EditorOpenSource.USER
}
});
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/e2e/tests/data-explorer/data-explorer-headless.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ async function testBody(app: Application, logger: Logger, fileName: string) {
async function openAsPlaintext(app: Application, fileName: string, searchString: string | RegExp) {
await app.workbench.quickaccess.openDataFile(join(app.workspacePathOrFolder, 'data-files', 'flights', fileName));
await app.workbench.quickaccess.runCommand('workbench.action.positronDataExplorer.openAsPlaintext');

const openAnyway = app.code.driver.page.getByText("Open Anyway");
if (await openAnyway.isVisible({ timeout: 1000 })) {
await openAnyway.click();
}

await app.workbench.editor.waitForEditorContents(fileName, (contents) => {
if (searchString instanceof RegExp) {
return contents.search(searchString) !== -1;
Expand Down

0 comments on commit 5d85617

Please sign in to comment.