org.eclipse.lsp4j.MessageParams Java Examples

The following examples show how to use org.eclipse.lsp4j.MessageParams. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultLanguageClient.java    From lsp4intellij with Apache License 2.0 6 votes vote down vote up
@Override
public void logMessage(MessageParams messageParams) {
    String message = messageParams.getMessage();
    MessageType msgType = messageParams.getType();

    if (msgType == MessageType.Error) {
        LOG.error(message);
    } else if (msgType == MessageType.Warning) {
        LOG.warn(message);
    } else if (msgType == MessageType.Info) {
        LOG.info(message);
    }
    if (msgType == MessageType.Log) {
        LOG.debug(message);
    } else {
        LOG.warn("Unknown message type for " + message);
    }
}
 
Example #2
Source File: LanguageClientAppender.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void append(LoggingEvent event) {

  MessageParams mp = new MessageParams();
  mp.setMessage(event.getMessage().toString());
  mp.setType(MessageType.Info);

  switch (event.getLevel().toInt()) {
    case Level.FATAL_INT:
    case Level.ERROR_INT:
      mp.setType(MessageType.Error);
      break;
    case Level.INFO_INT:
      mp.setType(MessageType.Info);
      break;
    case Level.WARN_INT:
      mp.setType(MessageType.Warning);
      break;
    default:
      return;
  }

  client.logMessage(mp);
}
 
Example #3
Source File: TextDocumentServiceImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> documentSymbol(DocumentSymbolParams params) {
    JavaSource js = getSource(params.getTextDocument().getUri());
    List<Either<SymbolInformation, DocumentSymbol>> result = new ArrayList<>();
    try {
        js.runUserActionTask(cc -> {
            cc.toPhase(JavaSource.Phase.RESOLVED);
            for (Element tel : cc.getTopLevelElements()) {
                DocumentSymbol ds = element2DocumentSymbol(cc, tel);
                if (ds != null)
                    result.add(Either.forRight(ds));
            }
        }, true);
    } catch (IOException ex) {
        //TODO: include stack trace:
        client.logMessage(new MessageParams(MessageType.Error, ex.getMessage()));
    }

    return CompletableFuture.completedFuture(result);
}
 
Example #4
Source File: DefaultLanguageClient.java    From lsp4intellij with Apache License 2.0 6 votes vote down vote up
@Override
public void showMessage(MessageParams messageParams) {
    String title = "Language Server message";
    String message = messageParams.getMessage();
    ApplicationUtils.invokeLater(() -> {
        MessageType msgType = messageParams.getType();
        if (msgType == MessageType.Error) {
            Messages.showErrorDialog(message, title);
        } else if (msgType == MessageType.Warning) {
            Messages.showWarningDialog(message, title);
        } else if (msgType == MessageType.Info) {
            Messages.showInfoMessage(message, title);
        } else if (msgType == MessageType.Log) {
            Messages.showInfoMessage(message, title);
        } else {
            LOG.warn("No message type for " + message);
        }
    });
}
 
Example #5
Source File: GroovyServicesSignatureHelpTests.java    From groovy-language-server with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() {
	workspaceRoot = Paths.get(System.getProperty("user.dir")).resolve(PATH_WORKSPACE);
	srcRoot = workspaceRoot.resolve(PATH_SRC);
	if (!Files.exists(srcRoot)) {
		srcRoot.toFile().mkdirs();
	}

	services = new GroovyServices(new CompilationUnitFactory());
	services.setWorkspaceRoot(workspaceRoot);
	services.connect(new LanguageClient() {

		@Override
		public void telemetryEvent(Object object) {

		}

		@Override
		public CompletableFuture<MessageActionItem> showMessageRequest(ShowMessageRequestParams requestParams) {
			return null;
		}

		@Override
		public void showMessage(MessageParams messageParams) {

		}

		@Override
		public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {

		}

		@Override
		public void logMessage(MessageParams message) {

		}
	});
}
 
Example #6
Source File: LauncherTest.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testNotification() throws IOException {
	MessageParams p = new MessageParams();
	p.setMessage("Hello World");
	p.setType(MessageType.Info);
	
	client.expectedNotifications.put("window/logMessage", p);
	serverLauncher.getRemoteProxy().logMessage(p);
	client.joinOnEmpty();
}
 
Example #7
Source File: ActionScriptServices.java    From vscode-as3mxml with Apache License 2.0 5 votes vote down vote up
/**
 * Renames a symbol at the specified document position.
 */
@Override
public CompletableFuture<WorkspaceEdit> rename(RenameParams params)
{
    return CompletableFutures.computeAsync(compilerWorkspace.getExecutorService(), cancelToken ->
    {
        cancelToken.checkCanceled();

        //make sure that the latest changes have been passed to
        //workspace.fileChanged() before proceeding
        if(realTimeProblemsChecker != null)
        {
            realTimeProblemsChecker.updateNow();
        }

        compilerWorkspace.startBuilding();
        try
        {
            RenameProvider provider = new RenameProvider(workspaceFolderManager, fileTracker);
            WorkspaceEdit result = provider.rename(params, cancelToken);
            if(result == null)
            {
                if (languageClient != null)
                {
                    MessageParams message = new MessageParams();
                    message.setType(MessageType.Info);
                    message.setMessage("You cannot rename this element.");
                    languageClient.showMessage(message);
                }
                return new WorkspaceEdit(new HashMap<>());
            }
            return result;
        }
        finally
        {
            compilerWorkspace.doneBuilding();
        }
    });
}
 
Example #8
Source File: JavaClientConnection.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Sends the message to the client, to be displayed on a UI element.
 *
 * @param type
 * @param msg
 */
public void showNotificationMessage(MessageType type, String msg){
	MessageParams $ = new MessageParams();
	$.setMessage(msg);
	$.setType(type);
	client.showMessage($);
}
 
Example #9
Source File: JavaClientConnection.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Sends the logMessage message back to the client as a notification
 * @param msg The message to send back to the client
 */
public void logMessage(MessageType type, String msg) {
	MessageParams $= new MessageParams();
	$.setMessage(msg);
	$.setType(type);
	client.logMessage($);
}
 
Example #10
Source File: GroovyServicesTypeDefinitionTests.java    From groovy-language-server with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() {
	workspaceRoot = Paths.get(System.getProperty("user.dir")).resolve(PATH_WORKSPACE);
	srcRoot = workspaceRoot.resolve(PATH_SRC);
	if (!Files.exists(srcRoot)) {
		srcRoot.toFile().mkdirs();
	}

	services = new GroovyServices(new CompilationUnitFactory());
	services.setWorkspaceRoot(workspaceRoot);
	services.connect(new LanguageClient() {

		@Override
		public void telemetryEvent(Object object) {

		}

		@Override
		public CompletableFuture<MessageActionItem> showMessageRequest(ShowMessageRequestParams requestParams) {
			return null;
		}

		@Override
		public void showMessage(MessageParams messageParams) {

		}

		@Override
		public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {

		}

		@Override
		public void logMessage(MessageParams message) {

		}
	});
}
 
Example #11
Source File: LspLogger.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** */
public void log(String messageString, MessageType type) {
	final LanguageClient lc = this.languageClient;
	if (lc == null) {
		return;
	}
	MessageParams message = new MessageParams();
	message.setMessage(messageString);
	message.setType(type);
	lc.logMessage(message);
}
 
Example #12
Source File: N4JSCommandService.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Visualize the collected performance data on the client and reset the data back to its initial state.
 *
 * @param access
 *            the language server access.
 * @param cancelIndicator
 *            the cancel indicator.
 */
@ExecutableCommandHandler(RESET_PERFORMANCE_DATA)
public Void resetPerformanceDataCollector(ILanguageServerAccess access, CancelIndicator cancelIndicator) {
	access.getLanguageClient()
			.logMessage(new MessageParams(MessageType.Log, DataCollectorUtils.allDataToString("  ")));
	access.getLanguageClient()
			.logMessage(new MessageParams(MessageType.Log, "Reset collected performance data"));
	CollectedDataAccess.resetAllData();
	return null;
}
 
Example #13
Source File: RdfLintLanguageServer.java    From rdflint with MIT License 5 votes vote down vote up
private void showException(String msg, Exception ex) {
  StringWriter w = new StringWriter();
  PrintWriter p = new PrintWriter(w);
  ex.printStackTrace(p);

  this.client.showMessage(
      new MessageParams(MessageType.Info,
          String.format("%s: %s: %s", msg, ex.getMessage(), w.toString())));
}
 
Example #14
Source File: XMLExternalTest.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
private static XMLLanguageServer createServer(List<PublishDiagnosticsParams> actualDiagnostics) {

		XMLLanguageServer languageServer = new XMLLanguageServer();
		XMLLanguageClientAPI client = new XMLLanguageClientAPI() {

			@Override
			public CompletableFuture<MessageActionItem> showMessageRequest(ShowMessageRequestParams requestParams) {
				return null;
			}

			@Override
			public void showMessage(MessageParams messageParams) {

			}

			@Override
			public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {
				actualDiagnostics.add(diagnostics);
			}

			@Override
			public void logMessage(MessageParams message) {

			}

			@Override
			public void telemetryEvent(Object object) {

			}

			@Override
			public void actionableNotification(ActionableNotification notification) {
				throw new UnsupportedOperationException();
			}
		};
		languageServer.setClient(client);
		return languageServer;
	}
 
Example #15
Source File: LSPClientLogHandler.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void publish(LogRecord record) {
	if (languageClient == null) {
		return;
	}

	String msg = formatRecord(record, Locale.getDefault());
	MessageType messageType = getMessageType(record.getLevel());
	MessageParams mp = new MessageParams(messageType, msg);
	languageClient.logMessage(mp);

}
 
Example #16
Source File: GroovyServicesCompletionTests.java    From groovy-language-server with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() {
	workspaceRoot = Paths.get(System.getProperty("user.dir")).resolve(PATH_WORKSPACE);
	srcRoot = workspaceRoot.resolve(PATH_SRC);
	if (!Files.exists(srcRoot)) {
		srcRoot.toFile().mkdirs();
	}

	services = new GroovyServices(new CompilationUnitFactory());
	services.setWorkspaceRoot(workspaceRoot);
	services.connect(new LanguageClient() {

		@Override
		public void telemetryEvent(Object object) {

		}

		@Override
		public CompletableFuture<MessageActionItem> showMessageRequest(ShowMessageRequestParams requestParams) {
			return null;
		}

		@Override
		public void showMessage(MessageParams messageParams) {

		}

		@Override
		public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {

		}

		@Override
		public void logMessage(MessageParams message) {

		}
	});
}
 
Example #17
Source File: GroovyServicesDefinitionTests.java    From groovy-language-server with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() {
	workspaceRoot = Paths.get(System.getProperty("user.dir")).resolve(PATH_WORKSPACE);
	srcRoot = workspaceRoot.resolve(PATH_SRC);
	if (!Files.exists(srcRoot)) {
		srcRoot.toFile().mkdirs();
	}

	services = new GroovyServices(new CompilationUnitFactory());
	services.setWorkspaceRoot(workspaceRoot);
	services.connect(new LanguageClient() {

		@Override
		public void telemetryEvent(Object object) {

		}

		@Override
		public CompletableFuture<MessageActionItem> showMessageRequest(ShowMessageRequestParams requestParams) {
			return null;
		}

		@Override
		public void showMessage(MessageParams messageParams) {

		}

		@Override
		public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {

		}

		@Override
		public void logMessage(MessageParams message) {

		}
	});
}
 
Example #18
Source File: XMLLanguageServer.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void sendNotification(String message, MessageType messageType, Command... commands) {
	SharedSettings sharedSettings = getSharedSettings();
	if (sharedSettings.isActionableNotificationSupport() && sharedSettings.isOpenSettingsCommandSupport()) {
		ActionableNotification notification = new ActionableNotification().withSeverity(messageType)
				.withMessage(message).withCommands(Arrays.asList(commands));
		languageClient.actionableNotification(notification);
	} else {
		// the open settings command is not supported by the client, display a simple
		// message with LSP
		languageClient.showMessage(new MessageParams(messageType, message));
	}		
}
 
Example #19
Source File: LanguageClientImpl.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public final void logMessage(MessageParams message) {
    CompletableFuture.runAsync(() -> ServerMessageHandler.logMessage(wrapper, message));
}
 
Example #20
Source File: XMLCapabilitiesTest.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void showMessage(MessageParams messageParams) {
}
 
Example #21
Source File: MockLanguageClient.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void logMessage(MessageParams message) {
}
 
Example #22
Source File: MockLanguageClient.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void showMessage(MessageParams messageParams) {
}
 
Example #23
Source File: XMLCapabilitiesTest.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void logMessage(MessageParams message) {
}
 
Example #24
Source File: CommandRegistryTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public void showMessage(MessageParams messageParams) {
	noImpl3.showMessage(messageParams);
}
 
Example #25
Source File: CommandRegistryTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public void logMessage(MessageParams message) {
	noImpl3.logMessage(message);
}
 
Example #26
Source File: ServerMessageHandler.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
public static void logMessage(LanguageServerWrapper wrapper, MessageParams params) {
    //TODO: implements message to console
}
 
Example #27
Source File: ServerMessageHandler.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
public static void showMessage(String title, MessageParams params) {
    Notification notification = new Notification("Language Server Protocol", messageTypeToIcon(params.getType()), title, null, params.getMessage(), messageTypeToNotificationType(params.getType()), null);
    Notifications.Bus.notify(notification);
}
 
Example #28
Source File: LanguageClientImpl.java    From intellij-quarkus with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public final void showMessage(MessageParams messageParams) {
    ServerMessageHandler.showMessage(wrapper.serverDefinition.label, messageParams);
}
 
Example #29
Source File: LanguageClientImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void logMessage(MessageParams arg0) {
    System.err.println("logMessage: " + arg0);
}
 
Example #30
Source File: LanguageClientImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void showMessage(MessageParams arg0) {
    System.err.println("showMessage: " + arg0);
}