LanguageClient: move match function to language filter

Change-Id: I9081d441fa2f48e5a1c5273e2de2620e0b88c4e0
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2019-03-11 15:13:36 +01:00
parent 34de118ee3
commit 89335266ba
3 changed files with 21 additions and 12 deletions

View File

@@ -674,21 +674,12 @@ void Client::setSupportedLanguage(const LanguageFilter &filter)
bool Client::isSupportedDocument(const Core::IDocument *document) const
{
QTC_ASSERT(document, return false);
return isSupportedFile(document->filePath(), document->mimeType());
return m_languagFilter.isSupported(document->filePath(), document->mimeType());
}
bool Client::isSupportedFile(const Utils::FileName &filePath, const QString &mimeType) const
{
if (m_languagFilter.mimeTypes.isEmpty() && m_languagFilter.filePattern.isEmpty())
return true;
if (m_languagFilter.mimeTypes.contains(mimeType))
return true;
auto regexps = Utils::transform(m_languagFilter.filePattern, [](const QString &pattern){
return QRegExp(pattern, Utils::HostOsInfo::fileNameCaseSensitivity(), QRegExp::Wildcard);
});
return Utils::anyOf(regexps, [filePath](const QRegExp &reg){
return reg.exactMatch(filePath.toString()) || reg.exactMatch(filePath.fileName());
});
return m_languagFilter.isSupported(filePath, mimeType);
}
bool Client::isSupportedUri(const DocumentUri &uri) const

View File

@@ -719,4 +719,18 @@ QString StdIOSettingsWidget::arguments() const
return m_arguments->text();
}
bool LanguageFilter::isSupported(const Utils::FileName &filePath, const QString &mimeType) const
{
if (mimeTypes.isEmpty() && filePattern.isEmpty())
return true;
if (mimeTypes.contains(mimeType))
return true;
auto regexps = Utils::transform(filePattern, [](const QString &pattern){
return QRegExp(pattern, Utils::HostOsInfo::fileNameCaseSensitivity(), QRegExp::Wildcard);
});
return Utils::anyOf(regexps, [filePath](const QRegExp &reg){
return reg.exactMatch(filePath.toString()) || reg.exactMatch(filePath.fileName());
});
}
} // namespace LanguageClient

View File

@@ -37,7 +37,10 @@ class QCheckBox;
class QLineEdit;
QT_END_NAMESPACE
namespace Utils { class PathChooser; }
namespace Utils {
class FileName;
class PathChooser;
} // namespace Utils
namespace LanguageClient {
@@ -50,6 +53,7 @@ struct LanguageFilter
{
QStringList mimeTypes;
QStringList filePattern;
bool isSupported(const Utils::FileName &filePath, const QString &mimeType) const;
};
class BaseSettings