-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Console] Monaco migration: send request and copy as curl buttons #179808
Changes from 9 commits
bb3d4fb
059277d
8d3de48
9aaf989
39466c8
5a109a4
e8d3c2e
d93ca6d
d57a527
c4e984a
5ffedbf
0e772d5
1904bc5
e5d9229
5efc013
0803622
90f1789
3d458e6
ece77c6
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ConsoleWorkerProxyService } from './console_worker_proxy'; | ||
import { CONSOLE_LANG_ID } from './constants'; | ||
import { monaco } from '../monaco_imports'; | ||
|
||
export const setupConsoleErrorsProvider = (workerProxyService: ConsoleWorkerProxyService) => { | ||
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. Might be helpful to add some documentation here that explains what this function does. |
||
const updateErrorMarkers = async (model: monaco.editor.IModel): Promise<void> => { | ||
if (model.isDisposed()) { | ||
return; | ||
} | ||
const parserResult = await workerProxyService.getParserResult(model.uri); | ||
|
||
if (!parserResult) { | ||
return; | ||
} | ||
const { errors } = parserResult; | ||
monaco.editor.setModelMarkers( | ||
model, | ||
CONSOLE_LANG_ID, | ||
errors.map(({ offset, text }) => { | ||
const { column, lineNumber } = model.getPositionAt(offset); | ||
return { | ||
startLineNumber: lineNumber, | ||
startColumn: column, | ||
endLineNumber: lineNumber, | ||
endColumn: column, | ||
message: text, | ||
severity: monaco.MarkerSeverity.Error, | ||
}; | ||
}) | ||
); | ||
}; | ||
const onModelAdd = (model: monaco.editor.IModel) => { | ||
if (model.getLanguageId() !== CONSOLE_LANG_ID) { | ||
return; | ||
} | ||
|
||
const { dispose } = model.onDidChangeContent(async () => { | ||
await updateErrorMarkers(model); | ||
}); | ||
|
||
model.onWillDispose(() => { | ||
dispose(); | ||
}); | ||
|
||
updateErrorMarkers(model); | ||
}; | ||
monaco.editor.onDidCreateModel(onModelAdd); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ConsoleWorkerProxyService } from './console_worker_proxy'; | ||
import { ParsedRequest } from './types'; | ||
import { monaco } from '../monaco_imports'; | ||
|
||
export class ConsoleParsedRequestsProvider { | ||
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. Documentation would be helpful here as well. |
||
constructor( | ||
private workerProxyService: ConsoleWorkerProxyService, | ||
private model: monaco.editor.ITextModel | null | ||
) {} | ||
public async getRequests(): Promise<ParsedRequest[]> { | ||
if (!this.model) { | ||
return []; | ||
} | ||
const parserResult = await this.workerProxyService.getParserResult(this.model.uri); | ||
return parserResult?.requests ?? []; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { monaco } from '../monaco_imports'; | ||
import { CONSOLE_LANG_ID } from './constants'; | ||
import { ConsoleParserResult, ConsoleWorkerDefinition } from './types'; | ||
|
||
export class ConsoleWorkerProxyService { | ||
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. this file is copied from the previously used file 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. Documentation would be helpful here as well. |
||
private worker: monaco.editor.MonacoWebWorker<ConsoleWorkerDefinition> | undefined; | ||
|
||
public async getParserResult(modelUri: monaco.Uri): Promise<ConsoleParserResult | undefined> { | ||
if (!this.worker) { | ||
throw new Error('Worker Proxy Service has not been setup!'); | ||
} | ||
await this.worker.withSyncedResources([modelUri]); | ||
const parser = await this.worker.getProxy(); | ||
return parser.getParserResult(modelUri.toString()); | ||
} | ||
|
||
public setup() { | ||
this.worker = monaco.editor.createWebWorker({ label: CONSOLE_LANG_ID, moduleId: '' }); | ||
} | ||
|
||
public stop() { | ||
if (this.worker) this.worker.dispose(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export interface ErrorAnnotation { | ||
offset: number; | ||
text: string; | ||
} | ||
|
||
export interface ParsedRequest { | ||
startOffset: number; | ||
endOffset: number; | ||
method: string; | ||
url: string; | ||
data?: Array<Record<string, unknown>>; | ||
} | ||
export interface ConsoleParserResult { | ||
errors: ErrorAnnotation[]; | ||
requests: ParsedRequest[]; | ||
} | ||
|
||
export interface ConsoleWorkerDefinition { | ||
getParserResult: (modelUri: string) => ConsoleParserResult | undefined; | ||
} | ||
export type ConsoleParser = (source: string) => ConsoleParserResult | undefined; |
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.
this file is copied from the previously used file
packages/kbn-monaco/src/ace_migration/setup_worker.ts