ecode: Added range formatting support. Improved behavior when closing tabs with mouse.

This commit is contained in:
Martín Lucas Golini
2023-07-02 18:57:23 -03:00
parent b68161b64e
commit 1f1f2b5c17
11 changed files with 140 additions and 42 deletions

View File

@@ -244,6 +244,37 @@ void LSPClientServerManager::requestSymanticHighlighting( std::shared_ptr<TextDo
}
}
static json getURIJSON( std::shared_ptr<TextDocument> doc ) {
json data;
json docUri;
json options;
docUri["uri"] = doc->getURI().toString();
data["textDocument"] = docUri;
options["tabSize"] = doc->getIndentWidth();
options["insertSpaces"] = doc->getIndentType() == TextDocument::IndentType::IndentSpaces;
data["options"] = options;
return data;
}
void LSPClientServerManager::rangeFormatting( std::shared_ptr<TextDocument> doc ) {
if ( !doc->getSelection().hasSelection() )
return;
mThreadPool->run( [this, doc] {
auto* server = getOneLSPClientServer( doc );
if ( server ) {
URI uri( doc->getURI() );
server->documentRangeFormatting(
uri, doc->getSelection(), getURIJSON( doc ),
[this, uri]( const PluginIDType&, const std::vector<LSPTextEdit>& edits ) {
mPluginManager->getSplitter()->getUISceneNode()->runOnMainThread(
[this, edits, uri] {
mPlugin->processDocumentFormattingResponse( uri, edits );
} );
} );
}
} );
}
void LSPClientServerManager::run( const std::shared_ptr<TextDocument>& doc ) {
mThreadPool->run( [&, doc]() { tryRunServer( doc ); } );
}