-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
158 additions
and
11 deletions.
There are no files selected for viewing
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
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
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
43 changes: 43 additions & 0 deletions
43
src/main/scala/com/neowit/response/protocols/lsp/AppVersion.scala
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,43 @@ | ||
/* | ||
* Copyright (c) 2018 Andrey Gavrikov. | ||
* this file is part of tooling-force.com application | ||
* https://github.com/neowit/tooling-force.com | ||
* | ||
* This program 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 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.neowit.response.protocols.lsp | ||
|
||
import com.neowit.apex.actions.ActionSuccess | ||
import com.neowit.response._ | ||
|
||
class AppVersion(writer: ResponseWriterLsp) extends LspProtocol[AppVersionResult] { | ||
def send(result: AppVersionResult): Unit = { | ||
val msg = | ||
result.appName + " - version: " + result.appVersion + | ||
"; SFDC API Version: " + result.sfdcApiVersion + | ||
"; java: " + result.javaVersion + | ||
"; OS: " + result.os | ||
|
||
writer.sendResponse(ActionSuccess(msg)) | ||
|
||
val mb = 1024*1024 | ||
val runtime = Runtime.getRuntime | ||
|
||
writer.debug( s"Used Memory: ${(runtime.totalMemory - runtime.freeMemory) / mb} MB") | ||
writer.debug( s"Free Memory: ${runtime.freeMemory / mb} MB") | ||
writer.debug( s"Total Memory: ${runtime.totalMemory / mb} MB") | ||
writer.debug( s"Max Memory: ${runtime.maxMemory / mb} MB") | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/main/scala/com/neowit/response/protocols/lsp/ResponseWriterLsp.scala
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,80 @@ | ||
/* | ||
* Copyright (c) 2018 Andrey Gavrikov. | ||
* this file is part of tooling-force.com application | ||
* https://github.com/neowit/tooling-force.com | ||
* | ||
* This program 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 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.neowit.response.protocols.lsp | ||
|
||
import java.io.{PrintWriter, StringWriter} | ||
|
||
import com.neowit.apex.actions.{ActionFailure, ActionResult, ActionSuccess} | ||
import com.neowit.apexscanner.server.protocol.LanguageServer | ||
import com.neowit.apexscanner.server.protocol.messages._ | ||
import com.neowit.response | ||
import com.neowit.response.{BaseResult, RESULT, ResponseWriter} | ||
import com.neowit.utils.Logging | ||
|
||
import io.circe.syntax._ | ||
/** | ||
* Created by Andrey Gavrikov | ||
*/ | ||
trait LspProtocol[A <: BaseResult] { | ||
def send(result: A): Unit | ||
} | ||
class ResponseWriterLsp(messageId: Int, server: LanguageServer) extends ResponseWriter with Logging with MessageJsonSupport { | ||
private var _responseMessage: Option[ResponseMessage] = None | ||
|
||
override def sendResponse(result: ActionResult): Unit = { | ||
// TODO - implement proper handling of messages and resultOpt | ||
|
||
result match { | ||
case ActionSuccess(messages, resultOpt) => | ||
val totalMessage = messages.mkString("; ") | ||
_responseMessage = Option(ResponseMessage(messageId, result = Option(totalMessage.asJson), error = None)) | ||
case ActionFailure(messages, resultOpt) => | ||
val totalMessage = messages.mkString("; ") | ||
val error = ResponseError(0, totalMessage, messageId = Option(messageId)) | ||
_responseMessage = Option(ResponseMessage(messageId, result = None, Option(error))) | ||
} | ||
} | ||
|
||
override def send(msg: response.Message): response.Message = throw new UnsupportedOperationException | ||
|
||
override def send(msg: String): Unit = throw new UnsupportedOperationException | ||
|
||
override def send(msg: RESULT): Unit = throw new UnsupportedOperationException | ||
|
||
override def sendError(msg: String, ex: Exception): Unit = { | ||
val sw = new StringWriter | ||
ex.printStackTrace(new PrintWriter(sw)) | ||
val stackTraceStr = sw.toString | ||
// dump exception information to log | ||
logger.error(ex.getMessage) | ||
logger.error(stackTraceStr) | ||
|
||
val err = ResponseError(0, msg + ex.getMessage + "\n" + stackTraceStr) | ||
_responseMessage = Option(ResponseMessage(messageId, result = None, error = Option(err))) | ||
} | ||
|
||
override def close(): Unit = () | ||
|
||
def debug(msg: String): Unit = { | ||
server.sendLogMessageNotification(MessageType.Log, msg) | ||
} | ||
|
||
def result(): Option[ResponseMessage] = _responseMessage | ||
} |