Skip to content

Commit 86f5abe

Browse files
committed
rework handling of uri to contents path in jump
1 parent bb39801 commit 86f5abe

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

packages/jupyterlab-lsp/src/features/jump_to.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ export class CMJumpToDefinition extends CodeMirrorIntegration {
5757

5858
if ('targetUri' in location_or_link) {
5959
return {
60-
uri: decodeURI(location_or_link.targetUri),
60+
uri: location_or_link.targetUri,
6161
range: location_or_link.targetRange
6262
};
6363
} else if ('uri' in location_or_link) {
6464
return {
65-
uri: decodeURI(location_or_link.uri),
65+
uri: location_or_link.uri,
6666
range: location_or_link.range
6767
};
6868
}
@@ -105,12 +105,10 @@ export class CMJumpToDefinition extends CodeMirrorIntegration {
105105
console.log('Jump target (source location):', source_position_ce);
106106

107107
// can it be resolved vs our guessed server root?
108-
const contents_path = uri_to_contents_path(uri);
108+
let contents_path = uri_to_contents_path(uri);
109109

110-
if (contents_path) {
111-
uri = contents_path;
112-
} else if (uri.startsWith('file://')) {
113-
uri = uri.slice(7);
110+
if (contents_path == null && uri.startsWith('file://')) {
111+
contents_path = decodeURI(uri.slice(7));
114112
}
115113

116114
let jump_data = {
@@ -124,17 +122,20 @@ export class CMJumpToDefinition extends CodeMirrorIntegration {
124122
// with different OSes but also with JupyterHub and other platforms.
125123

126124
try {
127-
await this.jumper.document_manager.services.contents.get(uri, {
128-
content: false
129-
});
130-
this.jumper.global_jump({ uri, ...jump_data }, false);
125+
await this.jumper.document_manager.services.contents.get(
126+
contents_path,
127+
{
128+
content: false
129+
}
130+
);
131+
this.jumper.global_jump({ uri: contents_path, ...jump_data }, false);
131132
return;
132133
} catch (err) {
133134
console.warn(err);
134135
}
135136

136137
this.jumper.global_jump(
137-
{ uri: '.lsp_symlink/' + uri, ...jump_data },
138+
{ uri: '.lsp_symlink/' + contents_path, ...jump_data },
138139
true
139140
);
140141
}

packages/jupyterlab-lsp/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export function uri_to_contents_path(child: string, parent?: string) {
136136
return null;
137137
}
138138
if (child.startsWith(parent)) {
139-
return child.replace(parent, '');
139+
return decodeURI(child.replace(parent, ''));
140140
}
141141
return null;
142142
}

packages/jupyterlab-lsp/src/virtual/document.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,10 +735,11 @@ export class VirtualDocument {
735735
}
736736

737737
get uri(): string {
738+
const encodedPath = encodeURI(this.path);
738739
if (!this.parent) {
739-
return this.path;
740+
return encodedPath;
740741
}
741-
return this.path + '.' + this.id_path + '.' + this.file_extension;
742+
return encodedPath + '.' + this.id_path + '.' + this.file_extension;
742743
}
743744

744745
transform_source_to_editor(pos: ISourcePosition): IEditorPosition {

0 commit comments

Comments
 (0)