Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/cm/lsp/tooltipExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
type ViewUpdate,
} from "@codemirror/view";
import { highlightCode } from "@lezer/highlight";
import { navigateToReference } from "components/referencesPanel/utils";
import type {
HoverParams,
ServerCapabilities,
Expand Down Expand Up @@ -348,6 +349,41 @@ function closeHoverIfNeeded(view: EditorView): void {
}
}

// Matches `#12`, `#L12`, `#L12,5`, `#12:5` style line/column fragments.
const FILE_LINK_FRAGMENT = /^#L?(\d+)(?:[,:Cc](\d+))?/;

/**
* Open `file://` links from LSP documentation in the editor instead of
* letting them bubble to the global handler, which would hand them to
* the system browser.
*/
function handleDocumentationLinks(dom: HTMLElement, view: EditorView): void {
dom.addEventListener("click", (event) => {
const link = (event.target as Element | null)?.closest?.("a[href]");
if (!link) return;
const href = link.getAttribute("href") || "";
if (!/^file:/i.test(href)) return;

event.preventDefault();
event.stopPropagation();

const hashIndex = href.indexOf("#");
const uri = hashIndex === -1 ? href : href.slice(0, hashIndex);
const match =
hashIndex === -1 ? null : FILE_LINK_FRAGMENT.exec(href.slice(hashIndex));
const position = {
line: match ? Math.max(0, Number(match[1]) - 1) : 0,
character: match?.[2] ? Math.max(0, Number(match[2]) - 1) : 0,
};

closeHoverIfNeeded(view);
void navigateToReference({
uri,
range: { start: position, end: position },
});
});
}

function hoverRequest(plugin: LSPPlugin, pos: number) {
if (!clientHasCapability(plugin.client, "hoverProvider")) {
return Promise.resolve(null);
Expand Down Expand Up @@ -417,6 +453,7 @@ function lspTooltipSource(
results[index].result.contents,
);
}
handleDocumentationLinks(dom, view);
return { dom };
},
above: true,
Expand Down Expand Up @@ -618,6 +655,7 @@ function drawSignatureTooltip(
const docs = dom.appendChild(document.createElement("div"));
docs.className = "cm-lsp-signature-documentation cm-lsp-documentation";
docs.innerHTML = plugin.docToHTML(signature.documentation);
handleDocumentationLinks(docs, view);
}
}

Expand Down
22 changes: 20 additions & 2 deletions src/plugins/system/android/com/foxdebug/system/System.java
Original file line number Diff line number Diff line change
Expand Up @@ -1682,8 +1682,26 @@ private void getAppInfo(CallbackContext callback) {
}

private void openInBrowser(String src, CallbackContext callback) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(src));
activity.startActivity(browserIntent);
if (src == null || src.isEmpty()) {
callback.error("No URL provided.");
return;
}

Uri uri = Uri.parse(src);
if ("file".equalsIgnoreCase(uri.getScheme())) {
// file:// URIs can't leave the app (FileUriExposedException).
callback.error("Cannot open file URI in browser: " + src);
return;
}

try {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri);
activity.startActivity(browserIntent);
callback.success();
} catch (Exception e) {
Log.e("System", "Failed to open URL: " + src, e);
callback.error(e.getMessage());
}
}

private void launchApp(
Expand Down
Loading