use of org.eclipse.lsp4j.Command in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method createCodeActionsForImport.
private void createCodeActionsForImport(Diagnostic diagnostic, List<Command> commands) {
String message = diagnostic.getMessage();
int start = message.lastIndexOf(" ") + 1;
int end = message.length() - 1;
String typeString = message.substring(start, end);
ArrayList<IDefinition> types = new ArrayList<>();
for (ICompilationUnit unit : compilationUnits) {
if (unit == null) {
continue;
}
try {
Collection<IDefinition> definitions = unit.getFileScopeRequest().get().getExternallyVisibleDefinitions();
if (definitions == null) {
continue;
}
for (IDefinition definition : definitions) {
if (definition instanceof ITypeDefinition) {
ITypeDefinition typeDefinition = (ITypeDefinition) definition;
String baseName = typeDefinition.getBaseName();
if (typeDefinition.getQualifiedName().equals(baseName)) {
//this definition is top-level. no import required.
continue;
}
if (baseName.equals(typeString)) {
types.add(typeDefinition);
}
}
}
} catch (Exception e) {
//safe to ignore
}
}
for (IDefinition definitionToImport : types) {
Command command = createImportCommand(definitionToImport);
if (command != null) {
commands.add(command);
}
}
}
use of org.eclipse.lsp4j.Command in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method codeAction.
/**
* Can be used to "quick fix" an error or warning.
*/
@Override
public CompletableFuture<List<? extends Command>> codeAction(CodeActionParams params) {
List<? extends Diagnostic> diagnostics = params.getContext().getDiagnostics();
TextDocumentIdentifier textDocument = params.getTextDocument();
Path path = LanguageServerUtils.getPathFromLanguageServerURI(textDocument.getUri());
if (path == null || !sourceByPath.containsKey(path)) {
return CompletableFuture.completedFuture(Collections.emptyList());
}
ArrayList<Command> commands = new ArrayList<>();
for (Diagnostic diagnostic : diagnostics) {
//I don't know why this can be null
String code = diagnostic.getCode();
if (code == null) {
continue;
}
switch(code) {
case //AccessUndefinedPropertyProblem
"1120":
{
//see if there's anything we can import
createCodeActionsForImport(diagnostic, commands);
break;
}
case //UnknownTypeProblem
"1046":
{
//see if there's anything we can import
createCodeActionsForImport(diagnostic, commands);
break;
}
case //InaccessiblePropertyReferenceProblem
"1178":
{
//see if there's anything we can import
createCodeActionsForImport(diagnostic, commands);
break;
}
case //CallUndefinedMethodProblem
"1180":
{
//see if there's anything we can import
createCodeActionsForImport(diagnostic, commands);
break;
}
}
}
return CompletableFuture.completedFuture(commands);
}
use of org.eclipse.lsp4j.Command in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method addDefinitionAutoCompleteActionScript.
private void addDefinitionAutoCompleteActionScript(IDefinition definition, CompletionList result) {
if (definition.getBaseName().startsWith(VECTOR_HIDDEN_PREFIX)) {
return;
}
CompletionItem item = new CompletionItem();
item.setKind(getDefinitionKind(definition));
item.setDetail(getDefinitionDetail(definition));
item.setLabel(definition.getBaseName());
boolean isInPackage = !definition.getQualifiedName().equals(definition.getBaseName());
if (isInPackage) {
Command command = createImportCommand(definition);
if (command != null) {
item.setCommand(command);
}
}
result.getItems().add(item);
}
use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.
the class DocumentLifeCycleHandler method handleOpen.
public void handleOpen(DidOpenTextDocumentParams params) {
String uri = params.getTextDocument().getUri();
ICompilationUnit unit = JDTUtils.resolveCompilationUnit(uri);
if (unit == null || unit.getResource() == null) {
return;
}
try {
// checks if the underlying resource exists and refreshes to sync the newly created file.
if (!unit.getResource().isAccessible()) {
try {
unit.getResource().refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor());
if (unit.getResource().exists()) {
IJavaElement parent = unit.getParent();
if (parent instanceof IPackageFragment) {
IPackageFragment pkg = (IPackageFragment) parent;
unit = pkg.createCompilationUnit(unit.getElementName(), unit.getSource(), true, new NullProgressMonitor());
}
}
} catch (CoreException e) {
// ignored
}
}
IProject project = unit.getResource().getProject();
// Resources belonging to the default project can only report syntax errors, because the project classpath is incomplete
boolean isDefaultProject = project.equals(JavaLanguageServerPlugin.getProjectsManager().getDefaultProject());
if (isDefaultProject || !JDTUtils.isOnClassPath(unit)) {
Severity severity = preferenceManager.getPreferences(project).getIncompleteClasspathSeverity();
String msg;
if (isDefaultProject) {
msg = "Classpath is incomplete. Only syntax errors will be reported";
} else {
msg = unit.getElementName() + " isn't on the classpath. Only syntax errors will be reported";
}
JavaLanguageServerPlugin.logInfo(msg + " for " + uri);
if (severity.compareTo(Preferences.Severity.ignore) > 0) {
ActionableNotification ignoreIncompleteClasspath = new ActionableNotification().withSeverity(severity.toMessageType()).withMessage(msg).withCommands(Arrays.asList(new Command("More Information", "java.ignoreIncompleteClasspath.help", null), new Command("Don't Show Again", "java.ignoreIncompleteClasspath", null)));
connection.sendActionableNotification(ignoreIncompleteClasspath);
}
}
// DiagnosticsHandler problemRequestor = new DiagnosticsHandler(connection, unit.getResource(), reportOnlySyntaxErrors);
unit.becomeWorkingCopy(new NullProgressMonitor());
IBuffer buffer = unit.getBuffer();
String newContent = params.getTextDocument().getText();
if (buffer != null && !buffer.getContents().equals(newContent)) {
buffer.setContents(newContent);
}
triggerValidation(unit);
// see https://github.com/redhat-developer/vscode-java/issues/274
checkPackageDeclaration(uri, unit);
} catch (JavaModelException e) {
JavaLanguageServerPlugin.logException("Error while opening document", e);
}
}
use of org.eclipse.lsp4j.Command in project eclipse.jdt.ls by eclipse.
the class ProjectsManager method fileChanged.
public void fileChanged(String uriString, CHANGE_TYPE changeType) {
if (uriString == null) {
return;
}
IResource resource = JDTUtils.findFile(uriString);
if (resource == null) {
return;
}
try {
if (changeType == CHANGE_TYPE.DELETED) {
resource = resource.getParent();
}
if (resource != null) {
resource.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
}
if (isBuildFile(resource)) {
FeatureStatus status = preferenceManager.getPreferences().getUpdateBuildConfigurationStatus();
switch(status) {
case automatic:
updateProject(resource.getProject());
break;
case disabled:
break;
default:
if (client != null) {
String cmd = "java.projectConfiguration.status";
TextDocumentIdentifier uri = new TextDocumentIdentifier(uriString);
ActionableNotification updateProjectConfigurationNotification = new ActionableNotification().withSeverity(MessageType.Info).withMessage("A build file was modified. Do you want to synchronize the Java classpath/configuration?").withCommands(asList(new Command("Never", cmd, asList(uri, FeatureStatus.disabled)), new Command("Now", cmd, asList(uri, FeatureStatus.interactive)), new Command("Always", cmd, asList(uri, FeatureStatus.automatic))));
client.sendActionableNotification(updateProjectConfigurationNotification);
}
}
}
} catch (CoreException e) {
JavaLanguageServerPlugin.logException("Problem refreshing workspace", e);
}
}
Aggregations