ecode: LSP - Don't fork a new process if the binary isn't available on the file system. Don't process notifications without method. Fix feature detection on initialize response when the server explicitly returns false for a feature.

This commit is contained in:
Martín Lucas Golini
2023-03-15 16:56:21 -03:00
parent fae07f495d
commit ec67e0b13f
3 changed files with 21 additions and 3 deletions

View File

@@ -294,7 +294,8 @@ static void fromJson( LSPServerCapabilities& caps, const json& json ) {
// so consider an object there as a (good?) sign that the server is suitably capable
auto toBoolOrObject = []( const nlohmann::json& value, const std::string& valueName ) {
return value.contains( valueName ) &&
( value[valueName].is_boolean() || value[valueName].is_object() );
( ( value[valueName].is_boolean() && value.value( valueName, false ) ) ||
value[valueName].is_object() );
};
auto& sync = json["textDocumentSync"];
@@ -1404,6 +1405,11 @@ void LSPClientServer::workDoneProgress( const LSPWorkDoneProgressParams& workDon
}
void LSPClientServer::processNotification( const json& msg ) {
if ( !msg.contains( MEMBER_METHOD ) ) {
Log::info( "LSPClientServer::processNotification - Unexpected notification, msg: %s",
msg.dump().c_str() );
return;
}
auto method = msg[MEMBER_METHOD].get<std::string>();
if ( method == "textDocument/publishDiagnostics" ) {
publishDiagnostics( msg );
@@ -1555,8 +1561,8 @@ void LSPClientServer::readStdOut( const char* bytes, size_t n ) {
Log::debug( "LSPClientServer::readStdOut server %s said:\n%s", mLSP.name.c_str(),
res.dump().c_str() );
HandlersMap::iterator it = mHandlers.end();
HandlersMap::iterator itEnd = mHandlers.end();
HandlersMap::iterator it;
HandlersMap::iterator itEnd;
JsonReplyHandler handlerOK;
JsonReplyHandler handlerErr;
bool handlerFound = false;

View File

@@ -83,6 +83,8 @@ void LSPClientServerManager::tryRunServer( const std::shared_ptr<TextDocument>&
return;
for ( const auto& lsp : lsps ) {
if ( !lsp.commandAvailable() )
continue;
std::string rootPath = mLSPWorkspaceFolder.isEmpty() ? findRootPath( lsp, doc )
: mLSPWorkspaceFolder.uri.getFSPath();
auto lspName = lsp.name.empty() ? lsp.command : lsp.name;

View File

@@ -1,9 +1,14 @@
#ifndef ECODE_LSPDEFINITION_HPP
#define ECODE_LSPDEFINITION_HPP
#include <eepp/core/string.hpp>
#include <eepp/system/sys.hpp>
#include <nlohmann/json.hpp>
#include <string>
#include <vector>
using namespace EE;
using namespace EE::System;
namespace ecode {
struct LSPDefinition {
@@ -17,6 +22,11 @@ struct LSPDefinition {
nlohmann::json initializationOptions;
bool disabled{ false };
bool commandAvailable() const {
auto cmdp( String::split( command, ' ' ) );
return !cmdp.empty() && !Sys::which( cmdp[0] ).empty();
}
};
} // namespace ecode