-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Наметки по аппендеру в language client
- Loading branch information
Showing
4 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
.../com/github/_1c_syntax/bsl/languageserver/infrastructure/LanguageClientAwareAppender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* This file is a part of BSL Language Server. | ||
* | ||
* Copyright (c) 2018-2023 | ||
* Alexey Sosnoviy <labotamy@gmail.com>, Nikita Fedkin <nixel2007@gmail.com> and contributors | ||
* | ||
* SPDX-License-Identifier: LGPL-3.0-or-later | ||
* | ||
* BSL Language Server is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3.0 of the License, or (at your option) any later version. | ||
* | ||
* BSL Language Server is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with BSL Language Server. | ||
*/ | ||
package com.github._1c_syntax.bsl.languageserver.infrastructure; | ||
|
||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.ConsoleAppender; | ||
import com.github._1c_syntax.bsl.languageserver.LanguageClientHolder; | ||
import jakarta.annotation.Nullable; | ||
import lombok.Setter; | ||
import org.eclipse.lsp4j.MessageParams; | ||
import org.eclipse.lsp4j.MessageType; | ||
import org.eclipse.lsp4j.services.LanguageClient; | ||
|
||
import java.io.IOException; | ||
|
||
public class LanguageClientAwareAppender | ||
extends ConsoleAppender<ILoggingEvent> { | ||
|
||
protected static LanguageClientAwareAppender INSTANCE; | ||
|
||
@Setter | ||
@Nullable | ||
private LanguageClientHolder clientHolder; | ||
|
||
public LanguageClientAwareAppender() { | ||
super(); | ||
// hacky hack | ||
INSTANCE = this; | ||
} | ||
|
||
@Override | ||
protected void writeOut(ILoggingEvent event) throws IOException { | ||
if (clientHolder != null && clientHolder.isConnected()) { | ||
LanguageClient languageClient = clientHolder.getClient().orElseThrow(); | ||
|
||
var params = new MessageParams(MessageType.Info, event.getFormattedMessage()); | ||
languageClient.logMessage(params); | ||
|
||
return; | ||
} | ||
super.writeOut(event); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...1c_syntax/bsl/languageserver/infrastructure/LanguageClientAwareAppenderConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* This file is a part of BSL Language Server. | ||
* | ||
* Copyright (c) 2018-2023 | ||
* Alexey Sosnoviy <labotamy@gmail.com>, Nikita Fedkin <nixel2007@gmail.com> and contributors | ||
* | ||
* SPDX-License-Identifier: LGPL-3.0-or-later | ||
* | ||
* BSL Language Server is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3.0 of the License, or (at your option) any later version. | ||
* | ||
* BSL Language Server is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with BSL Language Server. | ||
*/ | ||
package com.github._1c_syntax.bsl.languageserver.infrastructure; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class LanguageClientAwareAppenderConfiguration { | ||
|
||
@Bean | ||
public LanguageClientAwareAppender languageClientAwareAppender() { | ||
return LanguageClientAwareAppender.INSTANCE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
Console appender logback configuration provided for import, equivalent to the programmatic | ||
initialization performed by Boot | ||
--> | ||
|
||
<included> | ||
<appender name="LANGUAGE_CLIENT_AWARE" class="com.github._1c_syntax.bsl.languageserver.infrastructure.LanguageClientAwareAppender"> | ||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter"> | ||
<level>${CONSOLE_LOG_THRESHOLD}</level> | ||
</filter> | ||
<encoder> | ||
<pattern>${CONSOLE_LOG_PATTERN}</pattern> | ||
<charset>${CONSOLE_LOG_CHARSET}</charset> | ||
</encoder> | ||
</appender> | ||
</included> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<include resource="org/springframework/boot/logging/logback/defaults.xml"/> | ||
<include resource="language-client-aware-appender.xml" /> | ||
<root level="DEBUG"> | ||
<appender-ref ref="LANGUAGE_CLIENT_AWARE" /> | ||
</root> | ||
</configuration> |