Skip to content

Commit 78c8294

Browse files
snjezargrunber
authored andcommitted
Quickfixes should be available at the line level
Signed-off-by: Snjezana Peco <[email protected]>
1 parent dd6f006 commit 78c8294

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ The following settings are supported:
194194
* `java.settings.url` : Specifies the url or file path to the workspace Java settings. See [Setting Global Preferences](https://github.com/redhat-developer/vscode-java/wiki/Settings-Global-Preferences)
195195
* `java.symbols.includeSourceMethodDeclarations` : Include method declarations from source files in symbol search. Defaults to `false`.
196196

197+
New in 1.1.0:
198+
* `java.quickfix.showAt"` : Show quickfixes at the problem or line level.
199+
200+
197201
Semantic Highlighting
198202
===============
199203
[Semantic Highlighting](https://github.com/redhat-developer/vscode-java/wiki/Semantic-Highlighting) fixes numerous syntax highlighting issues with the default Java Textmate grammar. However, you might experience a few minor issues, particularly a delay when it kicks in, as it needs to be computed by the Java Language server, when opening a new file or when typing. Semantic highlighting can be disabled for all languages using the `editor.semanticHighlighting.enabled` setting, or for Java only using [language-specific editor settings](https://code.visualstudio.com/docs/getstarted/settings#_languagespecific-editor-settings).

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,16 @@
817817
"markdownDescription": "Include method declarations from source files in symbol search.",
818818
"default": false,
819819
"scope": "window"
820+
},
821+
"java.quickfix.showAt": {
822+
"type": "string",
823+
"enum": [
824+
"line",
825+
"problem"
826+
],
827+
"default": "line",
828+
"description": "Show quickfixes at the problem or line level.",
829+
"scope": "window"
820830
}
821831
}
822832
},

src/extension.ts

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import * as path from 'path';
44
import * as os from 'os';
55
import * as fs from 'fs';
66
import * as fse from 'fs-extra';
7-
import { workspace, extensions, ExtensionContext, window, commands, ViewColumn, Uri, languages, IndentAction, InputBoxOptions, EventEmitter, OutputChannel, TextDocument, RelativePattern, ConfigurationTarget, WorkspaceConfiguration, env, UIKind } from 'vscode';
8-
import { ExecuteCommandParams, ExecuteCommandRequest, LanguageClientOptions, RevealOutputChannelOn, ErrorHandler, Message, ErrorAction, CloseAction, DidChangeConfigurationNotification, CancellationToken } from 'vscode-languageclient';
7+
import { workspace, extensions, ExtensionContext, window, commands, ViewColumn, Uri, languages, IndentAction, InputBoxOptions, EventEmitter, OutputChannel, TextDocument, RelativePattern, ConfigurationTarget, WorkspaceConfiguration, env, UIKind, Selection, CodeActionContext, Diagnostic } from 'vscode';
8+
import { ExecuteCommandParams, ExecuteCommandRequest, LanguageClientOptions, RevealOutputChannelOn, ErrorHandler, Message, ErrorAction, CloseAction, DidChangeConfigurationNotification, CancellationToken, CodeActionRequest, CodeActionParams, Command } from 'vscode-languageclient';
99
import { LanguageClient } from 'vscode-languageclient/node';
1010
import { collectJavaExtensions, isContributedPartUpdated } from './plugin';
1111
import { prepareExecutable } from './javaServerStarter';
@@ -205,6 +205,55 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
205205
}
206206
});
207207
}
208+
},
209+
// https://github.com/redhat-developer/vscode-java/issues/2130
210+
// include all diagnostics for the current line in the CodeActionContext params for the performance reason
211+
provideCodeActions: (document, range, context, token, next) => {
212+
const client: any = standardClient.getClient();
213+
const params: CodeActionParams = {
214+
textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(document),
215+
range: client.code2ProtocolConverter.asRange(range),
216+
context: client.code2ProtocolConverter.asCodeActionContext(context)
217+
};
218+
const showAt = getJavaConfiguration().get<string>("quickfix.showAt");
219+
if (showAt === 'line' && range.start.line === range.end.line && range.start.character === range.end.character) {
220+
const textLine = document.lineAt(params.range.start.line);
221+
if (textLine !== null) {
222+
const diagnostics = client.diagnostics.get(document.uri);
223+
const allDiagnostics: Diagnostic[] = [];
224+
for (const diagnostic of diagnostics) {
225+
if (textLine.range.intersection(diagnostic.range)) {
226+
const newLen = allDiagnostics.push(diagnostic);
227+
if (newLen > 1000) {
228+
break;
229+
}
230+
}
231+
}
232+
const codeActionContext: CodeActionContext = {
233+
diagnostics: allDiagnostics,
234+
only: context.only,
235+
};
236+
params.context = client.code2ProtocolConverter.asCodeActionContext(codeActionContext);
237+
}
238+
}
239+
return client.sendRequest(CodeActionRequest.type, params, token).then((values) => {
240+
if (values === null) {
241+
return undefined;
242+
}
243+
const result = [];
244+
for (const item of values) {
245+
if (Command.is(item)) {
246+
result.push(client.protocol2CodeConverter.asCommand(item));
247+
}
248+
else {
249+
result.push(client.protocol2CodeConverter.asCodeAction(item));
250+
}
251+
}
252+
return result;
253+
}, (error) => {
254+
client.logFailedRequest(CodeActionRequest.type, error);
255+
return Promise.resolve([]);
256+
});
208257
}
209258
},
210259
revealOutputChannelOn: RevealOutputChannelOn.Never,

0 commit comments

Comments
 (0)