-
Notifications
You must be signed in to change notification settings - Fork 64
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
fix: playground error when returning a function declaration VSCODE-669 #925
Changes from 1 commit
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 |
---|---|---|
|
@@ -2,7 +2,6 @@ import { NodeDriverServiceProvider } from '@mongosh/service-provider-node-driver | |
import { ElectronRuntime } from '@mongosh/browser-runtime-electron'; | ||
import { parentPort } from 'worker_threads'; | ||
import { ServerCommands } from './serverCommands'; | ||
import type { Document } from 'bson'; | ||
|
||
import type { | ||
ShellEvaluateResult, | ||
|
@@ -17,7 +16,7 @@ interface EvaluationResult { | |
type: string | null; | ||
} | ||
|
||
const getContent = ({ type, printable }: EvaluationResult): Document => { | ||
const getContent = ({ type, printable }: EvaluationResult): any => { | ||
if (type === 'Cursor' || type === 'AggregationCursor') { | ||
return getEJSON(printable.documents); | ||
} | ||
|
@@ -27,11 +26,7 @@ const getContent = ({ type, printable }: EvaluationResult): Document => { | |
: getEJSON(printable); | ||
}; | ||
|
||
export const getLanguage = ( | ||
evaluationResult: EvaluationResult | ||
): 'json' | 'plaintext' => { | ||
const content = getContent(evaluationResult); | ||
|
||
export const getLanguage = (content: any): 'json' | 'plaintext' => { | ||
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. could also potentially be 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 should default to 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. was referring to 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. Ah, I see! I thought you were talking about the return type. |
||
if (typeof content === 'object' && content !== null) { | ||
return 'json'; | ||
} | ||
|
@@ -105,12 +100,19 @@ export const execute = async ({ | |
? `${source.namespace.db}.${source.namespace.collection}` | ||
: undefined; | ||
|
||
// The RPC protocol can't handle functions and it wouldn't make sense to return them anyway. Since just | ||
// declaring a function doesn't execute it, the best thing we can do is return undefined, similarly to | ||
// what we do when there's no return value from the script. | ||
const rpcSafePrintable = | ||
typeof printable !== 'function' ? printable : undefined; | ||
|
||
// Prepare a playground result. | ||
const content = getContent({ type, printable: rpcSafePrintable }); | ||
const result = { | ||
namespace, | ||
type: type ? type : typeof printable, | ||
content: getContent({ type, printable }), | ||
language: getLanguage({ type, printable }), | ||
type: type ? type : typeof rpcSafePrintable, | ||
content, | ||
language: getLanguage(content), | ||
}; | ||
|
||
return { data: { result } }; | ||
|
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.
could
unknown
be better?