Skip to content

Commit 862243d

Browse files
committed
Add serverDocumentUriForUri API function
1 parent 91e50ac commit 862243d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/extension.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,25 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
722722
apiVersion: active ? apiVersion : undefined,
723723
};
724724
},
725+
serverDocumentUriForUri(uri: vscode.Uri): vscode.Uri {
726+
const { apiTarget } = connectionTarget(uri);
727+
if (typeof apiTarget === "string") {
728+
// It was a file-type uri, so find its document (we hope it is open)
729+
const docs = vscode.workspace.textDocuments.filter((doc) => doc.uri === uri);
730+
let fileName = "";
731+
if (docs.length === 1) {
732+
// Found it, so work out the corresponding server-side name
733+
const file = currentFile(docs[0]);
734+
// For some local documents there is no server-side equivalent
735+
if (file) {
736+
fileName = file.name;
737+
}
738+
}
739+
// uri.path will be "/" if no mapping exists to a server-side equivalent
740+
uri = vscode.Uri.file(fileName).with({ scheme: OBJECTSCRIPT_FILE_SCHEMA, authority: apiTarget });
741+
}
742+
return uri;
743+
},
725744
};
726745

727746
// 'export' our public API

0 commit comments

Comments
 (0)