forked from qt-creator/qt-creator
QmlJS: Enable file name completion in imports.
Task-number: QTCREATORBUG-3067 Reviewed-by: Roberto Raggi
This commit is contained in:
@@ -620,6 +620,12 @@ bool CodeCompletion::completeUrl(const QString &relativeBasePath, const QString
|
|||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
return completeFileName(relativeBasePath, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CodeCompletion::completeFileName(const QString &relativeBasePath, const QString &fileName,
|
||||||
|
const QStringList &patterns)
|
||||||
|
{
|
||||||
const QFileInfo fileInfo(fileName);
|
const QFileInfo fileInfo(fileName);
|
||||||
QString directoryPrefix;
|
QString directoryPrefix;
|
||||||
if (fileInfo.isRelative()) {
|
if (fileInfo.isRelative()) {
|
||||||
@@ -632,12 +638,10 @@ bool CodeCompletion::completeUrl(const QString &relativeBasePath, const QString
|
|||||||
if (!QFileInfo(directoryPrefix).exists())
|
if (!QFileInfo(directoryPrefix).exists())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QDirIterator dirIterator(directoryPrefix);
|
QDirIterator dirIterator(directoryPrefix, patterns, QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot);
|
||||||
while (dirIterator.hasNext()) {
|
while (dirIterator.hasNext()) {
|
||||||
dirIterator.next();
|
dirIterator.next();
|
||||||
const QString fileName = dirIterator.fileName();
|
const QString fileName = dirIterator.fileName();
|
||||||
if (fileName == QLatin1String(".") || fileName == QLatin1String(".."))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
TextEditor::CompletionItem item(this);
|
TextEditor::CompletionItem item(this);
|
||||||
item.text += fileName;
|
item.text += fileName;
|
||||||
@@ -779,19 +783,29 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
|||||||
qmlScopeType = context->lookupType(document.data(), contextFinder.qmlObjectTypeName());
|
qmlScopeType = context->lookupType(document.data(), contextFinder.qmlObjectTypeName());
|
||||||
|
|
||||||
if (contextFinder.isInStringLiteral()) {
|
if (contextFinder.isInStringLiteral()) {
|
||||||
const Interpreter::Value *value = getPropertyValue(qmlScopeType, contextFinder.bindingPropertyName(), context);
|
// get the text of the literal up to the cursor position
|
||||||
|
|
||||||
if (!value) {
|
|
||||||
// do nothing
|
|
||||||
} else if (value->asUrlValue()) {
|
|
||||||
QTextCursor tc = edit->textCursor();
|
QTextCursor tc = edit->textCursor();
|
||||||
QmlExpressionUnderCursor expressionUnderCursor;
|
QmlExpressionUnderCursor expressionUnderCursor;
|
||||||
expressionUnderCursor(tc);
|
expressionUnderCursor(tc);
|
||||||
QString text = expressionUnderCursor.text();
|
QString literalText = expressionUnderCursor.text();
|
||||||
QTC_ASSERT(!text.isEmpty() && text.at(0) == QLatin1Char('"'), return -1);
|
QTC_ASSERT(!literalText.isEmpty() && (
|
||||||
text = text.mid(1);
|
literalText.at(0) == QLatin1Char('"')
|
||||||
|
|| literalText.at(0) == QLatin1Char('\'')), return -1);
|
||||||
|
literalText = literalText.mid(1);
|
||||||
|
|
||||||
if (completeUrl(document->path(), text))
|
if (contextFinder.isInImport()) {
|
||||||
|
QStringList patterns;
|
||||||
|
patterns << QLatin1String("*.qml") << QLatin1String("*.js");
|
||||||
|
if (completeFileName(document->path(), literalText, patterns))
|
||||||
|
return m_startPosition;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Interpreter::Value *value = getPropertyValue(qmlScopeType, contextFinder.bindingPropertyName(), context);
|
||||||
|
if (!value) {
|
||||||
|
// do nothing
|
||||||
|
} else if (value->asUrlValue()) {
|
||||||
|
if (completeUrl(document->path(), literalText))
|
||||||
return m_startPosition;
|
return m_startPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,9 @@ private:
|
|||||||
bool maybeTriggersCompletion(TextEditor::ITextEditable *editor);
|
bool maybeTriggersCompletion(TextEditor::ITextEditable *editor);
|
||||||
bool isDelimiter(QChar ch) const;
|
bool isDelimiter(QChar ch) const;
|
||||||
|
|
||||||
bool completeUrl(const QString &relativeBasePath, const QString &name);
|
bool completeUrl(const QString &relativeBasePath, const QString &urlString);
|
||||||
|
bool completeFileName(const QString &relativeBasePath, const QString &fileName,
|
||||||
|
const QStringList &patterns = QStringList());
|
||||||
|
|
||||||
void addCompletions(const QHash<QString, const QmlJS::Interpreter::Value *> &newCompletions,
|
void addCompletions(const QHash<QString, const QmlJS::Interpreter::Value *> &newCompletions,
|
||||||
const QIcon &icon, int relevance);
|
const QIcon &icon, int relevance);
|
||||||
|
|||||||
Reference in New Issue
Block a user