org.eclipse.lsp4j.MessageType Java Examples
The following examples show how to use
org.eclipse.lsp4j.MessageType.
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: LanguageClientAppender.java From saros with GNU General Public License v2.0 | 6 votes |
@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 #2
Source File: DefaultLanguageClient.java From lsp4intellij with Apache License 2.0 | 6 votes |
@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 #3
Source File: ServerMessageHandler.java From intellij-quarkus with Eclipse Public License 2.0 | 6 votes |
private static Icon messageTypeToIcon(MessageType type) { Icon result = null; switch (type) { case Error: result = AllIcons.General.Error; break; case Info: case Log: result = AllIcons.General.Information; break; case Warning: result = AllIcons.General.Warning; } return result; }
Example #4
Source File: ServerMessageHandler.java From intellij-quarkus with Eclipse Public License 2.0 | 6 votes |
private static NotificationType messageTypeToNotificationType(MessageType type) { NotificationType result = null; switch (type) { case Error: result = NotificationType.ERROR; break; case Info: case Log: result = NotificationType.INFORMATION; break; case Warning: result = NotificationType.WARNING; } return result; }
Example #5
Source File: TextDocumentServiceImpl.java From netbeans with Apache License 2.0 | 6 votes |
@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 #6
Source File: DefaultLanguageClient.java From lsp4intellij with Apache License 2.0 | 6 votes |
@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 #7
Source File: N4JSCommandService.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * 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 #8
Source File: LauncherTest.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@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 #9
Source File: ActionScriptServices.java From vscode-as3mxml with Apache License 2.0 | 5 votes |
/** * 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 #10
Source File: JavaClientConnection.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * 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 #11
Source File: JavaClientConnection.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * 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 #12
Source File: Preferences.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public MessageType toMessageType() { for (MessageType type : MessageType.values()) { if (name().equalsIgnoreCase(type.name())) { return type; } } //'ignore' has no MessageType equivalent return null; }
Example #13
Source File: LogHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private MessageType getMessageTypeFromSeverity(int severity) { switch (severity) { case IStatus.ERROR: return MessageType.Error; case IStatus.WARNING: return MessageType.Warning; case IStatus.INFO: return MessageType.Info; default: return MessageType.Log; } }
Example #14
Source File: LspLogger.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** */ 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 #15
Source File: RdfLintLanguageServer.java From rdflint with MIT License | 5 votes |
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 #16
Source File: LoggerTest.java From lemminx with Eclipse Public License 2.0 | 5 votes |
@BeforeEach public void startup() { TimeZone.setDefault(TimeZone.getTimeZone(("UTC"))); deleteLogFile(); mockLanguageClient = createLanguageClient(MessageType.Error, "Log Message"); LogsSettings settings = new LogsSettings(); // Enable log file settings.setFile(path); // Enable client settings.setClient(true); LogHelper.initializeRootLogger(mockLanguageClient, settings); logFile = new File(path); }
Example #17
Source File: DefaultLanguageClient.java From lsp4intellij with Apache License 2.0 | 5 votes |
@Override public CompletableFuture<MessageActionItem> showMessageRequest(ShowMessageRequestParams showMessageRequestParams) { List<MessageActionItem> actions = showMessageRequestParams.getActions(); String title = "Language Server message"; String message = showMessageRequestParams.getMessage(); MessageType msgType = showMessageRequestParams.getType(); Icon icon; if (msgType == MessageType.Error) { icon = UIUtil.getErrorIcon(); } else if (msgType == MessageType.Warning) { icon = UIUtil.getWarningIcon(); } else if (msgType == MessageType.Info) { icon = UIUtil.getInformationIcon(); } else if (msgType == MessageType.Log) { icon = UIUtil.getInformationIcon(); } else { icon = null; LOG.warn("No message type for " + message); } List<String> titles = new ArrayList<>(); for (MessageActionItem item : actions) { titles.add(item.getTitle()); } FutureTask<Integer> task = new FutureTask<>( () -> Messages.showDialog(message, title, (String[]) titles.toArray(), 0, icon)); ApplicationManager.getApplication().invokeAndWait(task); int exitCode = 0; try { exitCode = task.get(); } catch (InterruptedException | ExecutionException e) { LOG.warn(e.getMessage()); } return CompletableFuture.completedFuture(new MessageActionItem(actions.get(exitCode).getTitle())); }
Example #18
Source File: LSPClientLogHandler.java From lemminx with Eclipse Public License 2.0 | 5 votes |
@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 #19
Source File: LimitExceededWarner.java From lemminx with Eclipse Public License 2.0 | 5 votes |
/** * Send limit exceeded warning to client * * @param uri the file uri * @param resultLimit the result limit * @param feature the feature */ private void sendLimitExceededWarning(String uri, int resultLimit, LimitFeature feature) { String filename = Paths.get(URI.create(uri)).getFileName().toString(); String message = filename != null ? filename + ": " : ""; message += "For performance reasons, " + feature.getName() + " have been limited to " + resultLimit + " items.\nIf a new limit is set, please close and reopen this file to recompute " + feature.getName() + "."; // create command that opens the settings UI on the client side, in order to // quickly edit the setting Command command = new Command("Configure limit", ClientCommands.OPEN_SETTINGS, Collections.singletonList(feature.getSettingId())); super.sendNotification(message, MessageType.Info ,command); }
Example #20
Source File: InvalidPathWarner.java From lemminx with Eclipse Public License 2.0 | 5 votes |
private void sendInvalidFilePathWarning(Set<String> invalidPaths, PathFeature feature) { String message = createWarningMessage(feature.getSettingId(), invalidPaths); Command command = new Command("Configure setting", ClientCommands.OPEN_SETTINGS, Collections.singletonList(feature.getSettingId())); super.sendNotification(message, MessageType.Error, command); }
Example #21
Source File: LSPClientLogHandler.java From lemminx with Eclipse Public License 2.0 | 5 votes |
private static MessageType getMessageType(Level level) { if (level == Level.WARNING) { return MessageType.Warning; } if (level == Level.SEVERE) { return MessageType.Error; } return MessageType.Info; }
Example #22
Source File: XMLLanguageServer.java From lemminx with Eclipse Public License 2.0 | 5 votes |
@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 #23
Source File: LoggerTest.java From lemminx with Eclipse Public License 2.0 | 4 votes |
private MockLanguageClient createLanguageClient(MessageType messageType, String message) { MockLanguageClient newLanguageClient = new MockLanguageClient(messageType, message); return newLanguageClient; }
Example #24
Source File: MessageParams.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
/** * The message type. */ public void setType(@NonNull final MessageType type) { this.type = Preconditions.checkNotNull(type, "type"); }
Example #25
Source File: MessageParams.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
/** * The message type. */ @Pure @NonNull public MessageType getType() { return this.type; }
Example #26
Source File: MessageParams.java From lsp4j with Eclipse Public License 2.0 | 4 votes |
public MessageParams(@NonNull final MessageType type, @NonNull final String message) { this.type = Preconditions.<MessageType>checkNotNull(type, "type"); this.message = Preconditions.<String>checkNotNull(message, "message"); }
Example #27
Source File: JavaClientConnection.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
/** * Sends a message to the client to be presented to users, with possible * commands to execute */ public void sendActionableNotification(MessageType severity, String message, Object data, List<Command> commands) { ActionableNotification notification = new ActionableNotification().withSeverity(severity).withMessage(message).withData(data).withCommands(commands); sendActionableNotification(notification); }
Example #28
Source File: ActionableNotification.java From lemminx with Eclipse Public License 2.0 | 4 votes |
public ActionableNotification withSeverity(MessageType severity) { this.severity = severity; return this; }
Example #29
Source File: ActionableNotification.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
public ActionableNotification withSeverity(MessageType severity) { this.severity = severity; return this; }
Example #30
Source File: TextDocumentServiceImpl.java From netbeans with Apache License 2.0 | 4 votes |
@Override public CompletableFuture<List<? extends Location>> definition(TextDocumentPositionParams params) { JavaSource js = getSource(params.getTextDocument().getUri()); GoToTarget[] target = new GoToTarget[1]; LineMap[] lm = new LineMap[1]; try { js.runUserActionTask(cc -> { cc.toPhase(JavaSource.Phase.RESOLVED); Document doc = cc.getSnapshot().getSource().getDocument(true); int offset = getOffset(doc, params.getPosition()); Context context = GoToSupport.resolveContext(cc, doc, offset, false, false); if (context == null) { return ; } target[0] = GoToSupport.computeGoToTarget(cc, context, offset); lm[0] = cc.getCompilationUnit().getLineMap(); }, true); } catch (IOException ex) { //TODO: include stack trace: client.logMessage(new MessageParams(MessageType.Error, ex.getMessage())); } List<Location> result = new ArrayList<>(); if (target[0] != null && target[0].success) { if (target[0].offsetToOpen < 0) { Object[] openInfo = ElementOpenAccessor.getInstance().getOpenInfo(target[0].cpInfo, target[0].elementToOpen, new AtomicBoolean()); if (openInfo != null) { FileObject file = (FileObject) openInfo[0]; int start = (int) openInfo[1]; int end = (int) openInfo[2]; result.add(new Location(toUri(file), new Range(createPosition(lm[0], start), createPosition(lm[0], end)))); } } else { Position pos = createPosition(js.getFileObjects().iterator().next(), target[0].offsetToOpen); result.add(new Location(params.getTextDocument().getUri(), new Range(pos, pos))); } } return CompletableFuture.completedFuture(result); }