Fix TypeScript React and JavasSript React files in LSP, they were recognized as TypeScript and JavaScript files so it was incorrectly parsed.

This commit is contained in:
Martín Lucas Golini
2024-03-21 12:55:36 -03:00
parent 82ec47b5b7
commit bdc376a1eb
4 changed files with 35 additions and 3 deletions

View File

@@ -31,7 +31,7 @@
}
},
{
"language": "tsx",
"language": "typescriptreact",
"use": "typescript-language-server",
"share_process": true,
"file_patterns": ["%.tsx$"]
@@ -43,7 +43,7 @@
"file_patterns": ["%.js$"]
},
{
"language": "jsx",
"language": "javascriptreact",
"use": "typescript-language-server",
"share_process": true,
"file_patterns": ["%.jsx$"]

View File

@@ -770,6 +770,24 @@ void LSPClientPlugin::load( PluginManager* pluginManager ) {
}
}
std::unordered_map<std::string, std::unordered_map<std::string, std::string>> lspPatternsLangId;
for ( auto& lsp : lsps ) {
if ( lsp.shareProcessWithOtherDefinition && !lsp.usesLSP.empty() ) {
for ( const auto& ptrn : lsp.filePatterns )
lspPatternsLangId[lsp.usesLSP][ptrn] = lsp.language;
}
}
for ( auto& lsp : lsps ) {
auto ptrnsLangIds = lspPatternsLangId.find( lsp.name );
if ( ptrnsLangIds != lspPatternsLangId.end() ) {
lsp.languageIdsForFilePatterns.merge( ptrnsLangIds->second );
for ( const auto& ptrn : lsp.filePatterns )
lsp.languageIdsForFilePatterns[ptrn] = lsp.language;
}
}
mClientManager.load( this, pluginManager, std::move( lsps ) );
subscribeFileSystemListener();

View File

@@ -6,6 +6,7 @@
#include <eepp/system/iostreamstring.hpp>
#include <eepp/system/lock.hpp>
#include <eepp/system/log.hpp>
#include <eepp/system/luapattern.hpp>
#include <eepp/system/sys.hpp>
#include <eepp/ui/doc/textdocument.hpp>
#include <eepp/window/engine.hpp>
@@ -1433,7 +1434,18 @@ bool LSPClientServer::trimLogs() const {
LSPClientServer::LSPRequestHandle LSPClientServer::didOpen( const URI& document,
const std::string& text, int version ) {
auto params = textDocumentParams( textDocumentItem( document, mLSP.language, text, version ) );
std::string languageId = mLSP.language;
if ( !mLSP.languageIdsForFilePatterns.empty() ) {
for ( const auto& filePattern : mLSP.languageIdsForFilePatterns ) {
LuaPattern ptrn( filePattern.first );
if ( ptrn.matches( document.toString() ) ) {
languageId = filePattern.second;
break;
}
}
}
auto params = textDocumentParams( textDocumentItem( document, languageId, text, version ) );
return send( newRequest( "textDocument/didOpen", params ) );
}

View File

@@ -22,6 +22,8 @@ struct LSPDefinition {
std::string url;
std::string host;
std::unordered_map<std::string, std::string> env;
/* filePattern, languageId */
std::unordered_map<std::string, std::string> languageIdsForFilePatterns;
int port{ 0 };
nlohmann::json initializationOptions;