Skip to content
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
},
{
"command": "livePreview.setDefaultOpenFile",
"when": "resourceLangId == html",
"when": "resourceLangId == html && !inChat",
"group": "1_livepreview@2"
}
],
Expand Down
2 changes: 1 addition & 1 deletion src/editorPreview/previewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class PreviewManager extends Disposable {
let path = '/';
if (!connection?.workspace) {
this._notifyLooseFileOpen();
path = await this._endpointManager.encodeLooseFileEndpoint(file.fsPath);
path = await this._endpointManager.encodeLooseFileEndpoint(file);

if (!path.startsWith('/')) {
path = `/${path}`;
Expand Down
7 changes: 6 additions & 1 deletion src/infoManagers/endpointManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ export class EndpointManager extends Disposable {
* @param location the file location to encode.
* @returns the encoded endpoint.
*/
public async encodeLooseFileEndpoint(location: string): Promise<string> {
public async encodeLooseFileEndpoint(file: string | vscode.Uri): Promise<string> {
if (typeof file !== 'string' && file.scheme === 'vscode-chat-code-block') {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory we could try to handle all types of URIs that are not loose files on disk or untitled files, instead of just handling vscode-chat-code-block here but I didn't have enough confidence in what this method has to handle

return '/chatCodeBlock/' + encodeURIComponent(file.with({ fragment: '' }).toString());
}

const location = typeof file === 'string' ? file : file.fsPath;
let fullParent = await PathUtil.GetParentDir(location);
const child = await PathUtil.GetFileName(location, true);

Expand Down
1 change: 1 addition & 0 deletions src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ export class Manager extends Disposable {
serverGrouping?: ServerGrouping
): Promise<void> {
if (file.scheme !== 'file') {
// Is this an error?
console.error('Tried to open a non-file URI with file opener');
}
if (!serverGrouping) {
Expand Down
15 changes: 9 additions & 6 deletions src/server/httpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class HttpServer extends Disposable {
...(contentLength ? { 'Content-Length': contentLength } : {}),
// add CORP header for codespaces
// https://github.com/microsoft/vscode-livepreview/issues/560
...{'Cross-Origin-Resource-Policy': 'cross-origin'},
...{ 'Cross-Origin-Resource-Policy': 'cross-origin' },
...this._defaultHeaders
});
} catch (e) {
Expand Down Expand Up @@ -214,12 +214,15 @@ export class HttpServer extends Disposable {

let contentType = 'application/octet-stream';
if (basePath === '') {
if (URLPathName.startsWith('/endpoint_unsaved')) {
const untitledFileName = URLPathName.substring(
URLPathName.lastIndexOf('/') + 1
);
if (URLPathName.startsWith('/endpoint_unsaved') || URLPathName.startsWith('/chatCodeBlock')) {
let fileName: string;
if (URLPathName.startsWith('/endpoint_unsaved')) {
fileName = URLPathName.substring(URLPathName.lastIndexOf('/') + 1);
} else {
fileName = decodeURIComponent(URLPathName.slice('/chatCodeBlock/'.length));
}
const content = await this._contentLoader.getFileStream(
untitledFileName,
fileName,
false
);
if (content.Stream) {
Expand Down
2 changes: 1 addition & 1 deletion src/server/serverUtils/contentLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export class ContentLoader extends Disposable {
let contentLength = 0;

while (i < workspaceDocuments.length) {
if (PathUtil.PathEquals(readPath, workspaceDocuments[i].fileName)) {
if (PathUtil.PathEquals(readPath, workspaceDocuments[i].fileName) || (workspaceDocuments[i].uri.scheme === 'vscode-chat-code-block' && workspaceDocuments[i].uri.with({ fragment: '' }).toString() === readPath)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could put this thing .uri.with({ fragment: '' }).toString() in some utility, where's a good spot?

if (inFilesystem && workspaceDocuments[i].isUntitled) {
continue;
}
Expand Down