Skip to content

Commit ea5ff24

Browse files
committed
fix: shell resource leak when opening color dialog
in ColorInformationMining.UpdateColorWithDialog#accept
1 parent f49d26f commit ea5ff24

1 file changed

Lines changed: 26 additions & 21 deletions

File tree

org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/color/ColorInformationMining.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,32 +71,37 @@ public UpdateColorWithDialog(TextDocumentIdentifier textDocumentIdentifier, Colo
7171
public void accept(MouseEvent event) {
7272
final var styledText = (StyledText) event.widget;
7373
final var shell = new Shell(styledText.getDisplay());
74-
Rectangle location = Geometry.toDisplay(styledText, new Rectangle(event.x, event.y, 1, 1));
75-
shell.setLocation(location.x, location.y);
76-
// Open color dialog
77-
final var dialog = new ColorDialog(shell);
78-
dialog.setRGB(LSPEclipseUtils.toRGBA(colorInformation.getColor()).rgb);
79-
RGB rgb = dialog.open();
80-
if (rgb != null) {
81-
// get LSP color presentation list for the picked color
82-
final var params = new ColorPresentationParams(textDocumentIdentifier,
83-
LSPEclipseUtils.toColor(rgb), colorInformation.getRange());
84-
this.languageServerWrapper.execute(ls -> ls.getTextDocumentService().colorPresentation(params))
85-
.thenAcceptAsync(presentations -> {
86-
if (presentations == null || presentations.isEmpty()) {
87-
return;
88-
}
89-
// As ColorDialog cannot be customized (to choose the color presentation (rgb,
90-
// hexa, ....) we pick the first color presentation.
91-
TextEdit textEdit = presentations.get(0).getTextEdit();
74+
try {
75+
Rectangle location = Geometry.toDisplay(styledText, new Rectangle(event.x, event.y, 1, 1));
76+
shell.setLocation(location.x, location.y);
77+
// Open color dialog
78+
final var dialog = new ColorDialog(shell);
79+
dialog.setRGB(LSPEclipseUtils.toRGBA(colorInformation.getColor()).rgb);
80+
RGB rgb = dialog.open();
81+
if (rgb != null) {
82+
// get LSP color presentation list for the picked color
83+
final var params = new ColorPresentationParams(textDocumentIdentifier, LSPEclipseUtils.toColor(rgb),
84+
colorInformation.getRange());
85+
this.languageServerWrapper.execute(ls -> ls.getTextDocumentService() //
86+
.colorPresentation(params)) //
87+
.thenAcceptAsync(presentations -> {
88+
if (presentations == null || presentations.isEmpty()) {
89+
return;
90+
}
91+
// As ColorDialog cannot be customized (to choose the color presentation (rgb,
92+
// hexa, ....) we pick the first color presentation.
93+
TextEdit textEdit = presentations.get(0).getTextEdit();
9294
try {
93-
// TODO: Should consider using optimistic locking for this in case document changes while
94-
// request being processed
95+
// TODO: Should consider using optimistic locking for this in case document
96+
// changes while request being processed
9597
LSPEclipseUtils.applyEdit(textEdit, document);
9698
} catch (BadLocationException e) {
9799
LanguageServerPlugin.logError(e);
98100
}
99-
}, styledText.getDisplay());
101+
}, styledText.getDisplay());
102+
}
103+
} finally {
104+
shell.dispose();
100105
}
101106
}
102107
}

0 commit comments

Comments
 (0)