Skip to content

Commit

Permalink
feat(registry): serve docset pages over HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
trollixx committed Jan 28, 2020
1 parent 1d0fd8b commit e6a5334
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
Original file line number Diff line number Diff line change
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 @@ -563,8 +563,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 @@ -709,6 +710,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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(docset->documentPath(), name);
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 e6a5334

Please sign in to comment.