Changeset View
Changeset View
Standalone View
Standalone View
addons/lspclient/lspclientservermanager.cpp
Show First 20 Lines • Show All 419 Lines • ▼ Show 20 Line(s) | 416 | { | |||
---|---|---|---|---|---|
420 | } else if (server->state() == LSPClientServer::State::None) { | 420 | } else if (server->state() == LSPClientServer::State::None) { | ||
421 | // went down | 421 | // went down | ||
422 | showMessage(i18n("Server terminated unexpectedly: %1", server->cmdline().join(QLatin1Char(' '))), | 422 | showMessage(i18n("Server terminated unexpectedly: %1", server->cmdline().join(QLatin1Char(' '))), | ||
423 | KTextEditor::Message::Warning); | 423 | KTextEditor::Message::Warning); | ||
424 | restart(server); | 424 | restart(server); | ||
425 | } | 425 | } | ||
426 | } | 426 | } | ||
427 | 427 | | |||
428 | QJsonValue applyCustomInit(const QJsonValue & init, | | |||
429 | const QStringList & cmdline, const QUrl & root, QObject * projectView) | | |||
430 | { | | |||
431 | (void)root; | | |||
432 | | ||||
433 | // clangd specific | | |||
434 | if (cmdline.at(0).indexOf(QStringLiteral("clangd")) >= 0) { | | |||
435 | const auto& projectMap = projectView ? projectView->property("projectMap").toMap() : QVariantMap(); | | |||
436 | // prefer the build directory, if set, e.g. for CMake generated .kateproject files | | |||
437 | auto buildDir = projectMap.value(QStringLiteral("build")).toMap().value(QStringLiteral("directory")).toString(); | | |||
438 | // fallback to base directory of .kateproject file if build doesn't contain a compilation database | | |||
439 | if (buildDir.isEmpty() || !QFile::exists(buildDir + QStringLiteral("/compile_commands.json"))) { | | |||
440 | buildDir = projectView ? projectView->property("projectBaseDir").toString() : QString(); | | |||
441 | } | | |||
442 | auto obinit = init.toObject(); | | |||
443 | // NOTE: | | |||
444 | // alternatively, use symlink to have clang locate the db by parent dir search | | |||
445 | // which allows it to handle multiple compilation db | | |||
446 | // (since this custom way only allows passing it to a specific instance) | | |||
447 | // FIXME perhaps also use workspace/didChangeConfiguration to update compilation db ?? | | |||
448 | // (but symlink is then simpler for now ;-) ) | | |||
449 | // ... at which time need a nicer way to involve server specific interventions | | |||
450 | obinit[QStringLiteral("compilationDatabasePath")] = buildDir; | | |||
451 | return obinit; | | |||
452 | } | | |||
453 | return init; | | |||
454 | } | | |||
455 | | ||||
456 | QSharedPointer<LSPClientServer> | 428 | QSharedPointer<LSPClientServer> | ||
457 | _findServer(KTextEditor::Document *document) | 429 | _findServer(KTextEditor::Document *document) | ||
458 | { | 430 | { | ||
459 | QObject *projectView = m_mainWindow->pluginView(QStringLiteral("kateprojectplugin")); | 431 | QObject *projectView = m_mainWindow->pluginView(QStringLiteral("kateprojectplugin")); | ||
460 | const auto projectBase = QDir(projectView ? projectView->property("projectBaseDir").toString() : QString()); | 432 | const auto projectBase = QDir(projectView ? projectView->property("projectBaseDir").toString() : QString()); | ||
461 | const auto& projectMap = projectView ? projectView->property("projectMap").toMap() : QVariantMap(); | 433 | const auto& projectMap = projectView ? projectView->property("projectMap").toMap() : QVariantMap(); | ||
462 | 434 | | |||
463 | auto mode = document->highlightingMode(); | 435 | auto mode = document->highlightingMode(); | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 480 | if (!server) { | |||
512 | if (!scmdline.isEmpty()) { | 484 | if (!scmdline.isEmpty()) { | ||
513 | cmdline = scmdline.split(QLatin1Char(' ')); | 485 | cmdline = scmdline.split(QLatin1Char(' ')); | ||
514 | } else { | 486 | } else { | ||
515 | for (const auto& c : vcmdline.toArray()) { | 487 | for (const auto& c : vcmdline.toArray()) { | ||
516 | cmdline.push_back(c.toString()); | 488 | cmdline.push_back(c.toString()); | ||
517 | } | 489 | } | ||
518 | } | 490 | } | ||
519 | if (cmdline.length() > 0) { | 491 | if (cmdline.length() > 0) { | ||
520 | auto&& init = serverConfig.value(QStringLiteral("initializationOptions")); | 492 | server.reset(new LSPClientServer(cmdline, root, serverConfig.value(QStringLiteral("initializationOptions")))); | ||
521 | init = applyCustomInit(init, cmdline, root, projectView); | | |||
522 | server.reset(new LSPClientServer(cmdline, root, init)); | | |||
523 | m_servers[root][mode] = server; | 493 | m_servers[root][mode] = server; | ||
524 | connect(server.get(), &LSPClientServer::stateChanged, | 494 | connect(server.get(), &LSPClientServer::stateChanged, | ||
525 | this, &self_type::onStateChanged, Qt::UniqueConnection); | 495 | this, &self_type::onStateChanged, Qt::UniqueConnection); | ||
526 | if (!server->start()) { | 496 | if (!server->start()) { | ||
527 | showMessage(i18n("Failed to start server: %1", cmdline.join(QLatin1Char(' '))), | 497 | showMessage(i18n("Failed to start server: %1", cmdline.join(QLatin1Char(' '))), | ||
528 | KTextEditor::Message::Error); | 498 | KTextEditor::Message::Error); | ||
529 | } | 499 | } | ||
530 | } | 500 | } | ||
▲ Show 20 Lines • Show All 155 Lines • Show Last 20 Lines |