Skip to content

Commit

Permalink
feat(registry): serve docset pages over HTTP
Browse files Browse the repository at this point in the history
Fixes #1160.
  • Loading branch information
trollixx committed Feb 25, 2020
1 parent e3bd300 commit 6dc7531
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/libs/registry/docset.cpp
Expand Up @@ -194,7 +194,7 @@ Docset::Docset(QString path)
m_indexFilePath = QStringLiteral("index.html");
}

// Log if unable to determine the index page.
// Log if unable to determine the index page. Otherwise the path will be set in setBaseUrl().
if (m_indexFilePath.isEmpty()) {
qWarning("Cannot determine index file for docset %s", qPrintable(m_name));
m_indexFileUrl.setUrl(NotFoundPageUrl);
Expand Down Expand Up @@ -567,8 +567,9 @@ QUrl Docset::createPageUrl(const QString &path, const QString &fragment) const
realPath.remove(dashEntryRegExp);
realFragment.remove(dashEntryRegExp);

// Absolute file path is required here to handle relative path to the docset storage (see #806).
QUrl url = QUrl::fromLocalFile(QDir(documentPath()).absoluteFilePath(realPath));
QUrl url = m_baseUrl;
url.setPath(m_baseUrl.path() + "/" + realPath, QUrl::TolerantMode);

if (!realFragment.isEmpty()) {
if (realFragment.startsWith(QLatin1String("//apple_ref"))
|| realFragment.startsWith(QLatin1String("//dash_ref"))) {
Expand Down Expand Up @@ -715,6 +716,20 @@ QString Docset::parseSymbolType(const QString &str)
return aliases.value(str, str);
}

QUrl Docset::baseUrl() const
{
return m_baseUrl;
}

void Docset::setBaseUrl(const QUrl &baseUrl)
{
m_baseUrl = baseUrl;

if (!m_indexFilePath.isEmpty()) {
m_indexFileUrl = createPageUrl(m_indexFilePath);
}
}

bool Docset::isFuzzySearchEnabled() const
{
return m_fuzzySearchEnabled;
Expand Down
5 changes: 5 additions & 0 deletions src/libs/registry/docset.h
Expand Up @@ -77,6 +77,9 @@ class Docset final
// FIXME: This is an ugly workaround before we have a proper docset sources implementation
bool hasUpdate = false;

QUrl baseUrl() const;
void setBaseUrl(const QUrl &baseUrl);

bool isFuzzySearchEnabled() const;
void setFuzzySearchEnabled(bool enabled);

Expand Down Expand Up @@ -118,6 +121,8 @@ class Docset final
Util::SQLiteDatabase *m_db = nullptr;
bool m_fuzzySearchEnabled = false;
bool m_javaScriptEnabled = false;

QUrl m_baseUrl;
};

} // namespace Registry
Expand Down
15 changes: 15 additions & 0 deletions src/libs/registry/docsetregistry.cpp
Expand Up @@ -28,6 +28,9 @@
#include "searchquery.h"
#include "searchresult.h"

#include <core/application.h>
#include <core/httpserver.h>

#include <QDir>
#include <QThread>

Expand Down Expand Up @@ -139,7 +142,19 @@ void DocsetRegistry::loadDocset(const QString &path)
unloadDocset(name);
}

// Setup HTTP mount.
QUrl url = Core::Application::instance()->httpServer()->mount(name, docset->documentPath());
if (url.isEmpty()) {
qWarning("Could not enable docset from '%s'. Reinstall the docset.",
qPrintable(docset->path()));
delete docset;
return;
}

docset->setBaseUrl(url);

m_docsets[name] = docset;

emit docsetLoaded(name);
});

Expand Down

0 comments on commit 6dc7531

Please sign in to comment.