Skip to content
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

Support DocumentDropEditProvider (#12025) #12125

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
review changes
Signed-off-by: Jonah Iden <jonah.iden@typefox.io>
  • Loading branch information
jonah-iden committed Feb 10, 2023
commit 1d3a7ae641ac98e10341096f91278939c5dfb866
3 changes: 2 additions & 1 deletion packages/filesystem/src/node/node-file-upload-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ export class NodeFileUploadService implements BackendApplicationContribution {
}
try {
const target = FileUri.fsPath(fields.uri);
if (!fields.leaveInTemp) { // if dont move the file, just leave it where it is
if (!fields.leaveInTemp) {
await fs.move(request.file.path, target, { overwrite: true });
} else {
// leave the file where it is, just rename it to its original name
fs.rename(request.file.path, request.file.path.replace(request.file.filename, request.file.originalname));
}
response.status(200).send(target); // ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,13 @@ export namespace DataTransferItem {

export namespace DataTransfer {
export async function toDataTransferDTO(value: VSDataTransfer): Promise<DataTransferDTO> {
const newDTO: DataTransferDTO = { items: [] };

const promises: Promise<unknown>[] = [];

value.forEach((val, key) => {
promises.push((async () => {
newDTO.items.push([key, await DataTransferItem.from(key, val)]);
})());
});

await Promise.all(promises);

return newDTO;
return {
items: await Promise.all(
Array.from(value.entries())
.map(
async ([mime, item]) => [mime, await DataTransferItem.from(mime, item)]
)
)
};
}
}
21 changes: 10 additions & 11 deletions packages/plugin-ext/src/main/browser/languages-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
} from '../../common/plugin-api-rpc-model';
import { RPCProtocol } from '../../common/rpc-protocol';
import { MonacoLanguages, WorkspaceSymbolProvider } from '@theia/monaco/lib/browser/monaco-languages';
import CoreURI, { URI } from '@theia/core/lib/common/uri';
import { URI } from '@theia/core/lib/common/uri';
import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
import { Emitter, Event } from '@theia/core/lib/common/event';
import { ProblemManager } from '@theia/markers/lib/browser';
Expand Down Expand Up @@ -260,13 +260,13 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {

$clearDiagnostics(id: string): void {
for (const uri of this.problemManager.getUris()) {
this.problemManager.setMarkers(new CoreURI(uri), id, []);
this.problemManager.setMarkers(new URI(uri), id, []);
}
}

$changeDiagnostics(id: string, delta: [string, MarkerData[]][]): void {
for (const [uriString, markers] of delta) {
const uri = new CoreURI(uriString);
const uri = new URI(uriString);
this.problemManager.setMarkers(uri, id, markers.map(reviveMarker));
}
}
Expand Down Expand Up @@ -739,14 +739,13 @@ export class LanguagesMainImpl implements LanguagesMain, Disposable {
protected async provideDocumentDropEdits(handle: number, model: ITextModel, position: monaco.IPosition,
dataTransfer: VSDataTransfer, token: CancellationToken): Promise<DocumentOnDropEdit | undefined> {
await this.fileUploadService.upload(new URI(), { source: dataTransfer, leaveInTemp: true });
return this.proxy.$provideDocumentDropEdits(handle, model.uri, position, await DataTransfer.toDataTransferDTO(dataTransfer), token).then(edit => {
if (edit) {
return {
insertText: edit.insertText instanceof SnippetString ? { snippet: edit.insertText.value } : edit.insertText,
additionalEdit: toMonacoWorkspaceEdit(edit?.additionalEdit)
};
}
});
const edit = await this.proxy.$provideDocumentDropEdits(handle, model.uri, position, await DataTransfer.toDataTransferDTO(dataTransfer), token);
if (edit) {
return {
insertText: edit.insertText instanceof SnippetString ? { snippet: edit.insertText.value } : edit.insertText,
additionalEdit: toMonacoWorkspaceEdit(edit?.additionalEdit)
};
}
}

$registerFoldingRangeProvider(handle: number, pluginInfo: PluginInfo, selector: SerializedDocumentFilter[], eventHandle: number | undefined): void {
Expand Down