-
Notifications
You must be signed in to change notification settings - Fork 209
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
Do not send uuid-named temp files to the client #4142
Changes from 7 commits
ee69947
583ee7e
bbe59c9
6d5d931
f02a6a5
b6a8332
e32176c
fb59911
6979182
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import path from 'node:path' | |
import * as uuid from 'uuid' | ||
import type * as vscode from 'vscode' | ||
|
||
import { logDebug, logError, setClientNameVersion } from '@sourcegraph/cody-shared' | ||
import { extensionForLanguage, logDebug, logError, setClientNameVersion } from '@sourcegraph/cody-shared' | ||
|
||
// <VERY IMPORTANT - PLEASE READ> | ||
// This file must not import any module that transitively imports from 'vscode'. | ||
|
@@ -292,10 +292,12 @@ const _workspace: typeof vscode.workspace = { | |
throw new Error('workspaceDocuments is uninitialized') | ||
} | ||
|
||
const uri = toUri(uriOrString) | ||
if (uri) { | ||
if (uri.scheme === 'untitled') await openUntitledDocument(uri) | ||
return workspaceDocuments.openTextDocument(uri) | ||
const result = toUri(uriOrString) | ||
if (result) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is causing tests hanging because the way I think part of the problem is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's unclear to me in this PR why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks Olaf, I think I was confused for a moment what is a client and what is a server code there, silly error on my side. /edit
So maybe at least a comment. |
||
if (result.uri.scheme === 'untitled' && result.shouldOpenInClient) { | ||
await openUntitledDocument(result.uri) | ||
} | ||
return workspaceDocuments.openTextDocument(result.uri) | ||
} | ||
return Promise.reject( | ||
new Error(`workspace.openTextDocument:unsupported argument ${JSON.stringify(uriOrString)}`) | ||
|
@@ -452,20 +454,32 @@ const defaultTreeView: vscode.TreeView<any> = { | |
title: undefined, | ||
} | ||
|
||
/** | ||
* @returns An object with a URI and a boolean indicating whether the URI should be opened in the client. | ||
* This object with UUID path is used only when we want to create in-memory temp files, and those we do not want to send to the clients. | ||
*/ | ||
function toUri( | ||
uriOrString: string | vscode.Uri | { language?: string; content?: string } | undefined | ||
): Uri | undefined { | ||
): { uri: Uri; shouldOpenInClient: boolean } | undefined { | ||
if (typeof uriOrString === 'string') { | ||
return Uri.file(uriOrString) | ||
return { uri: Uri.file(uriOrString), shouldOpenInClient: true } | ||
} | ||
if (uriOrString instanceof Uri) { | ||
return uriOrString | ||
return { uri: uriOrString, shouldOpenInClient: true } | ||
} | ||
if ( | ||
typeof uriOrString === 'object' && | ||
((uriOrString as any)?.language || (uriOrString as any)?.content) | ||
) { | ||
return Uri.from({ scheme: 'untitled', path: `${uuid.v4()}` }) | ||
const language = (uriOrString as any)?.language ?? '' | ||
const extension = extensionForLanguage(language) ?? language | ||
return { | ||
uri: Uri.from({ | ||
scheme: 'untitled', | ||
path: `${uuid.v4()}.${extension}`, | ||
}), | ||
shouldOpenInClient: false, | ||
} | ||
} | ||
return | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks fragile :) Which document are we getting there, the one with UUID in the name or the real one? Maybe we can get it by name or filter out the second one, so it will be clear what is going on there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed