configyaml link provider

This commit is contained in:
Nate 2025-03-24 08:57:56 -07:00
parent 009e88bbe0
commit a9d0d9723a
6 changed files with 113 additions and 33 deletions

View file

@ -1,12 +1,12 @@
{
"name": "continue",
"version": "1.1.13",
"version": "1.1.15",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "continue",
"version": "1.1.13",
"version": "1.1.15",
"license": "Apache-2.0",
"dependencies": {
"@continuedev/fetch": "^1.0.3",
@ -106,7 +106,7 @@
"@aws-sdk/client-sagemaker-runtime": "^3.758.0",
"@aws-sdk/credential-providers": "^3.758.0",
"@continuedev/config-types": "^1.0.13",
"@continuedev/config-yaml": "^1.0.63",
"@continuedev/config-yaml": "^1.0.67",
"@continuedev/fetch": "^1.0.4",
"@continuedev/llm-info": "^1.0.2",
"@continuedev/openai-adapters": "^1.0.18",

View file

@ -0,0 +1,43 @@
import * as vscode from "vscode";
export class ConfigYamlDocumentLinkProvider
implements vscode.DocumentLinkProvider
{
private usesPattern = /^\s*#?\s*-\s*uses:\s*(.+)$/;
provideDocumentLinks(
document: vscode.TextDocument,
token: vscode.CancellationToken,
): vscode.ProviderResult<vscode.DocumentLink[]> {
const links: vscode.DocumentLink[] = [];
for (let lineIndex = 0; lineIndex < document.lineCount; lineIndex++) {
const line = document.lineAt(lineIndex);
const match = this.usesPattern.exec(line.text);
if (match) {
const slug = match[1].trim();
const startPos = line.text.indexOf(slug);
const range = new vscode.Range(
lineIndex,
startPos,
lineIndex,
startPos + slug.length,
);
const link = new vscode.DocumentLink(
range,
vscode.Uri.parse(`https://hub.continue.dev/${slug}`),
);
links.push(link);
}
}
return links;
}
resolveDocumentLink(
link: vscode.DocumentLink,
token: vscode.CancellationToken,
): vscode.ProviderResult<vscode.DocumentLink> {
return link;
}
}

View file

@ -37,6 +37,7 @@ import { Battery } from "../util/battery";
import { FileSearch } from "../util/FileSearch";
import { VsCodeIde } from "../VsCodeIde";
import { ConfigYamlDocumentLinkProvider } from "./ConfigYamlDocumentLinkProvider";
import { VsCodeMessenger } from "./VsCodeMessenger";
import type { VsCodeWebviewProtocol } from "../webviewProtocol";
@ -401,6 +402,12 @@ export class VsCodeExtension {
),
);
const linkProvider = vscode.languages.registerDocumentLinkProvider(
{ language: "yaml" },
new ConfigYamlDocumentLinkProvider(),
);
context.subscriptions.push(linkProvider);
this.ide.onDidChangeActiveTextEditor((filepath) => {
void this.core.invoke("didChangeActiveTextEditor", { filepath });
});

View file

@ -0,0 +1,52 @@
import { ConfigYaml } from "@continuedev/config-yaml";
import { PencilIcon } from "@heroicons/react/24/outline";
import { useContext } from "react";
import { useAuth } from "../../../context/Auth";
import { IdeMessengerContext } from "../../../context/IdeMessenger";
type SectionKey = Exclude<keyof ConfigYaml, "name" | "version" | "schema">;
interface EditBlockButtonProps<T extends SectionKey> {
blockType: T;
block?: NonNullable<ConfigYaml[T]>[number];
className?: string;
}
function isUsesBlock(block: any): block is { uses: string } {
return typeof block !== "string" && "uses" in block;
}
export default function EditBlockButton<T extends SectionKey>({
block,
blockType,
className = "",
}: EditBlockButtonProps<T>) {
const ideMessenger = useContext(IdeMessengerContext);
const { selectedProfile } = useAuth();
const openUrl = (path: string) =>
ideMessenger.request("controlPlane/openUrl", {
path,
orgSlug: undefined,
});
const handleEdit = () => {
if (selectedProfile?.profileType === "local") {
ideMessenger.post("config/openProfile", {
profileId: undefined,
});
} else if (block && isUsesBlock(block)) {
openUrl(`${block.uses}/new-version`);
} else if (selectedProfile?.fullSlug) {
const slug = `${selectedProfile.fullSlug.ownerSlug}/${selectedProfile.fullSlug.packageSlug}`;
openUrl(`${slug}/new-version`);
}
};
return (
<PencilIcon
className={`h-3 w-3 cursor-pointer text-gray-400 hover:brightness-125 ${className}`}
onClick={handleEdit}
/>
);
}

View file

@ -2,12 +2,10 @@ import { ConfigYaml } from "@continuedev/config-yaml";
import {
ArrowPathIcon,
ArrowTopRightOnSquareIcon,
PencilIcon,
StopIcon,
} from "@heroicons/react/24/outline";
import { SiteIndexingConfig } from "core";
import { useContext, useMemo, useState } from "react";
import { useAuth } from "../../../../../context/Auth";
import { IdeMessengerContext } from "../../../../../context/IdeMessenger";
import { useAppDispatch, useAppSelector } from "../../../../../redux/hooks";
import { updateIndexingStatus } from "../../../../../redux/slices/indexingSlice";
@ -17,22 +15,18 @@ import {
} from "../../../../../redux/slices/uiSlice";
import { fontSize } from "../../../../../util";
import ConfirmationDialog from "../../../../dialogs/ConfirmationDialog";
import EditBlockButton from "../../EditBlockButton";
import { StatusIndicator } from "./StatusIndicator";
interface IndexingStatusViewerProps {
docConfig: SiteIndexingConfig;
docFromYaml?: NonNullable<ConfigYaml["docs"]>[number];
}
function isUsesBlock(block: any): block is { uses: string } {
return typeof block !== "string" && "uses" in block;
}
function DocsIndexingStatus({
docConfig,
docFromYaml,
}: IndexingStatusViewerProps) {
const ideMessenger = useContext(IdeMessengerContext);
const { selectedProfile } = useAuth();
const dispatch = useAppDispatch();
const status = useAppSelector(
@ -78,25 +72,6 @@ function DocsIndexingStatus({
dispatch(setShowDialog(true));
};
const openUrl = (path: string) =>
ideMessenger.request("controlPlane/openUrl", {
path,
orgSlug: undefined,
});
const handleEdit = () => {
console.log("edit", docFromYaml);
if (selectedProfile?.profileType === "local") {
ideMessenger.post("config/openProfile", {
profileId: undefined,
});
} else if (docFromYaml && isUsesBlock(docFromYaml)) {
openUrl(`${docFromYaml.uses}/new-version`);
} else if (selectedProfile?.fullSlug) {
const slug = `${selectedProfile.fullSlug.ownerSlug}/${selectedProfile.fullSlug.packageSlug}`;
openUrl(`${slug}/new-version`);
}
};
const progressPercentage = useMemo(() => {
if (!status) {
return 0;
@ -172,10 +147,7 @@ function DocsIndexingStatus({
/>
)}
<PencilIcon
className="h-3 w-3 cursor-pointer text-gray-400 hover:brightness-125"
onClick={handleEdit}
/>
<EditBlockButton blockType="docs" block={docFromYaml} />
{/* Removed StatusIndicator from here */}
</div>

View file

@ -346,6 +346,12 @@ export async function resolveBlock(
// Retrieve block raw yaml
const rawYaml = await registry.getContent(fullSlug);
if (rawYaml === undefined) {
throw new Error(
`Block ${fullSlug.ownerSlug}/${fullSlug.packageSlug} not found`,
);
}
// Convert any input secrets to FQSNs (they get FQSNs as if they are in the block. This is so that we know when to use models add-on / free trial secrets)
const renderedInputs = inputsToFQSNs(inputs || {}, fullSlug);