qmljs: add option to disable builtin codemodel

Add an option in the QML Language Server settings to disable the code
model, for now it allows to use qmlls for renaming and find usages
operations.
Some of the checkboxes in the qmlls settings were not making a lot of
sense, rephrased them to be easier to understand for the user.

TODOs for later commits:
* use qmlls for 'go to definition' aka 'follow symbol under cursor'
* add extra action to the context menu for 'go to type definition' and
  implement it using the language client
  * also, remove builtin codemode stuff from the context menu when the
    builtin model is disabled

Task-number: QTCREATORBUG-29567
Change-Id: I6283d99bd2b5dc8aef7df49994eb313bfbb854c6
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Sami Shalayel
2023-09-01 11:40:37 +02:00
parent 7082d2a89b
commit 25e1266c26
3 changed files with 50 additions and 7 deletions

View File

@@ -60,6 +60,10 @@
#include <utils/qtcassert.h>
#include <utils/uncommentselection.h>
#include <languageclient/languageclientmanager.h>
#include <languageclient/locatorfilter.h>
#include <languageclient/languageclientsymbolsupport.h>
#include <QComboBox>
#include <QCoreApplication>
#include <QFileInfo>
@@ -855,14 +859,39 @@ void QmlJSEditorWidget::findLinkAt(const QTextCursor &cursor,
processLinkCallback(Utils::Link());
}
static LanguageClient::Client *getQmllsClient(const Utils::FilePath &fileName)
{
// the value in disableBuiltinCodemodel is only valid when useQmlls is enabled
if (QmlJsEditingSettings::get().qmllsSettings().useQmlls
&& !QmlJsEditingSettings::get().qmllsSettings().disableBuiltinCodemodel)
return nullptr;
auto client = LanguageClient::LanguageClientManager::clientForFilePath(fileName);
return client;
}
void QmlJSEditorWidget::findUsages()
{
m_findReferences->findUsages(textDocument()->filePath(), textCursor().position());
const Utils::FilePath fileName = textDocument()->filePath();
if (auto client = getQmllsClient(fileName)) {
client->symbolSupport().findUsages(textDocument(), textCursor());
} else {
const int offset = textCursor().position();
m_findReferences->findUsages(fileName, offset);
}
}
void QmlJSEditorWidget::renameSymbolUnderCursor()
{
m_findReferences->renameUsages(textDocument()->filePath(), textCursor().position());
const Utils::FilePath fileName = textDocument()->filePath();
if (auto client = getQmllsClient(fileName)) {
client->symbolSupport().renameSymbol(textDocument(), textCursor(), QString());
} else {
const int offset = textCursor().position();
m_findReferences->renameUsages(fileName, offset);
}
}
void QmlJSEditorWidget::showContextPane()