Skip to content

Commit ef2f5d0

Browse files
committed
move logic under if statement and remove copied asRange
1 parent 1200905 commit ef2f5d0

File tree

1 file changed

+28
-33
lines changed

1 file changed

+28
-33
lines changed

src/extension.ts

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -317,43 +317,44 @@ export async function activate(context: ExtensionContext): Promise<ExtensionAPI>
317317
}
318318
const docChanges = result.edit !== undefined ? result.edit.documentChanges : undefined;
319319
if (docChanges !== undefined) {
320-
for (const editType of docChanges) {
321-
if ("textDocument" in editType) {
322-
for (const edit of editType.edits) {
320+
for (const docChange of docChanges) {
321+
if ("textDocument" in docChange) {
322+
for (const edit of docChange.edits) {
323323
if ("snippet" in edit) {
324-
documentUris.push(editType.textDocument.uri);
325-
snippetEdits.push(new SnippetTextEdit(asRange((edit as any).range), new SnippetString((edit as any).snippet.value)));
324+
documentUris.push(docChange.textDocument.uri);
325+
snippetEdits.push(new SnippetTextEdit(client.protocol2CodeConverter.asRange((edit as any).range), new SnippetString((edit as any).snippet.value)));
326326
}
327327
}
328328
}
329329
}
330-
}
331-
const codeAction = await client.protocol2CodeConverter.asCodeAction(result, token);
332-
const docEdits = codeAction.edit !== undefined? codeAction.edit.entries() : [];
333-
const newWorkspaceEdit = new WorkspaceEdit();
334-
for (const doc of docEdits) {
335-
const uri = doc[0];
336-
if (documentUris.includes(uri.toString())) {
337-
const editList = [];
338-
for (const edit of doc[1]) {
339-
let isSnippet = false;
340-
snippetEdits.forEach((snippet, index) => {
341-
if (edit.range.isEqual(snippet.range) && documentUris[index] === uri.toString()) {
342-
editList.push(snippet);
343-
isSnippet = true;
330+
const codeAction = await client.protocol2CodeConverter.asCodeAction(result, token);
331+
const docEdits = codeAction.edit !== undefined? codeAction.edit.entries() : [];
332+
const newWorkspaceEdit = new WorkspaceEdit();
333+
for (const docEdit of docEdits) {
334+
const uri = docEdit[0];
335+
if (documentUris.includes(uri.toString())) {
336+
const editList = [];
337+
for (const edit of docEdit[1]) {
338+
let isSnippet = false;
339+
snippetEdits.forEach((snippet, index) => {
340+
if (edit.range.isEqual(snippet.range) && documentUris[index] === uri.toString()) {
341+
editList.push(snippet);
342+
isSnippet = true;
343+
}
344+
});
345+
if (!isSnippet) {
346+
editList.push(edit);
344347
}
345-
});
346-
if (!isSnippet) {
347-
editList.push(edit);
348348
}
349+
newWorkspaceEdit.set(uri, editList);
350+
} else {
351+
newWorkspaceEdit.set(uri, docEdit[1]);
349352
}
350-
newWorkspaceEdit.set(uri, editList);
351-
} else {
352-
newWorkspaceEdit.set(uri, doc[1]);
353353
}
354+
codeAction.edit = newWorkspaceEdit;
355+
return codeAction;
354356
}
355-
codeAction.edit = newWorkspaceEdit;
356-
return codeAction;
357+
return await client.protocol2CodeConverter.asCodeAction(result, token);
357358
}, (error) => {
358359
return client.handleFailedRequest(CodeActionResolveRequest.type, token, error, item);
359360
});
@@ -1245,9 +1246,3 @@ function registerRestartJavaLanguageServerCommand(context: ExtensionContext) {
12451246
}
12461247
}));
12471248
}
1248-
1249-
function asRange(value) {
1250-
return value ? new Range(value.start.line, value.start.character, value.end.line, value.end.character) : undefined;
1251-
}
1252-
1253-

0 commit comments

Comments
 (0)