| 444 | } |
| 445 | |
| 446 | PluginRequestHandle LinterPlugin::processMessage( const PluginMessage& notification ) { |
| 447 | if ( notification.type == PluginMessageType::UIReady ) { |
| 448 | if ( mBrokenUserConfigFile ) |
| 449 | displayBrokenUserConfigFileWarning(); |
| 450 | return {}; |
| 451 | } |
| 452 | |
| 453 | if ( notification.type == PluginMessageType::FileSystemListenerReady ) { |
| 454 | subscribeFileSystemListener(); |
| 455 | return {}; |
| 456 | } |
| 457 | |
| 458 | if ( notification.type == PluginMessageType::DiagnosticsCodeAction && |
| 459 | notification.format == PluginMessageFormat::JSON && notification.isRequest() ) { |
| 460 | PluginIDType id( std::numeric_limits<Int64>::max() ); |
| 461 | TextDocument* doc = getDocumentFromURI( notification.asJSON().value( "uri", "" ) ); |
| 462 | if ( doc ) { |
| 463 | Lock l( mMatchesMutex ); |
| 464 | auto foundMatch = mMatches.find( doc ); |
| 465 | if ( foundMatch == mMatches.end() ) |
| 466 | return {}; |
| 467 | |
| 468 | auto pos = TextPosition::fromString( notification.asJSON().value( "pos", "" ) ); |
| 469 | if ( !pos.isValid() ) |
| 470 | return {}; |
| 471 | |
| 472 | auto foundLine = foundMatch->second.find( pos.line() ); |
| 473 | if ( foundLine == foundMatch->second.end() ) |
| 474 | return {}; |
| 475 | |
| 476 | LSPDiagnosticsCodeAction quickFix; |
| 477 | for ( const auto& match : foundLine->second ) { |
| 478 | if ( !match.diagnostic.codeActions.empty() ) { |
| 479 | for ( const auto& ca : match.diagnostic.codeActions ) { |
| 480 | quickFix = ca; |
| 481 | if ( quickFix.isPreferred ) |
| 482 | break; |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | mManager->sendResponse( this, PluginMessageType::DiagnosticsCodeAction, |
| 488 | PluginMessageFormat::DiagnosticsCodeAction, &quickFix, id ); |
| 489 | } |
| 490 | |
| 491 | return {}; |
| 492 | } |
| 493 | |
| 494 | if ( notification.type == PluginMessageType::GetErrorOrWarning && |
| 495 | notification.format == PluginMessageFormat::JSON && notification.isRequest() ) { |
| 496 | const json& j = notification.asJSON(); |
| 497 | if ( !j.contains( "uri" ) || !j.contains( "line" ) || !j.contains( "character" ) ) |
| 498 | return {}; |
| 499 | URI uri( j["uri"].get<std::string>() ); |
| 500 | TextDocument* doc = getDocumentFromURI( uri ); |
| 501 | if ( nullptr == doc ) |
| 502 | return {}; |
| 503 |
nothing calls this directly
no test coverage detected