uri util fixes
This commit is contained in:
parent
38b0ede53a
commit
24834edb65
8 changed files with 17 additions and 21 deletions
|
|
@ -6,7 +6,7 @@ export function rifWithContentsToContextItem(
|
|||
rif: RangeInFileWithContents,
|
||||
): ContextItemWithId {
|
||||
const basename = getUriPathBasename(rif.filepath);
|
||||
const { relativePathOrBasename } = findUriInDirs(
|
||||
const { relativePathOrBasename, foundInDir, uri } = findUriInDirs(
|
||||
rif.filepath,
|
||||
window.workspacePaths ?? [],
|
||||
);
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ export async function inferResolvedUriFromRelativePath(
|
|||
dirCandidates?: string[],
|
||||
): Promise<string> {
|
||||
const dirs = dirCandidates ?? (await ide.getWorkspaceDirs());
|
||||
console.log(path, dirs);
|
||||
if (dirs.length === 0) {
|
||||
throw new Error("inferResolvedUriFromRelativePath: no dirs provided");
|
||||
}
|
||||
|
|
@ -50,7 +51,6 @@ export async function inferResolvedUriFromRelativePath(
|
|||
dir,
|
||||
partialUri: joinPathsToUri(dir, suffix),
|
||||
}));
|
||||
console.log("here");
|
||||
const promises = uris.map(async ({ partialUri, dir }) => {
|
||||
const exists = await ide.fileExists(partialUri);
|
||||
return {
|
||||
|
|
@ -59,7 +59,6 @@ export async function inferResolvedUriFromRelativePath(
|
|||
exists,
|
||||
};
|
||||
});
|
||||
console.log("INFERRING", suffix, promises);
|
||||
const existenceChecks = await Promise.all(promises);
|
||||
|
||||
const existingUris = existenceChecks.filter(({ exists }) => exists);
|
||||
|
|
|
|||
|
|
@ -42,9 +42,11 @@ export function findUriInDirs(
|
|||
|
||||
// At this point we break the path up and check if each dir path part matches
|
||||
const dirPathParts = (dirComps.path ?? "")
|
||||
.replace(/^\//, "")
|
||||
.split("/")
|
||||
.map((part) => encodeURIComponent(part));
|
||||
const uriPathParts = (uriComps.path ?? "")
|
||||
.replace(/^\//, "")
|
||||
.split("/")
|
||||
.map((part) => encodeURIComponent(part));
|
||||
|
||||
|
|
@ -58,11 +60,10 @@ export function findUriInDirs(
|
|||
}
|
||||
}
|
||||
if (allDirPartsMatch) {
|
||||
const relativePath = uriPathParts.slice(dirPathParts.length).join("/");
|
||||
return {
|
||||
uri,
|
||||
relativePathOrBasename: uriPathParts
|
||||
.slice(dirPathParts.length)
|
||||
.join("/"),
|
||||
relativePathOrBasename: relativePath,
|
||||
foundInDir: dir,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ class VsCodeIde implements IDE {
|
|||
}
|
||||
|
||||
async fileExists(uri: string): Promise<boolean> {
|
||||
console.log("VSCODE FILE EXISTS");
|
||||
try {
|
||||
await vscode.workspace.fs.stat(vscode.Uri.parse(uri));
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -41,10 +41,10 @@ export default function CodeToEditCard() {
|
|||
}
|
||||
}
|
||||
|
||||
async function onSelectFilesToAdd(filepaths: string[]) {
|
||||
const filePromises = filepaths.map(async (filepath) => {
|
||||
const contents = await ideMessenger.ide.readFile(filepath);
|
||||
return { contents, filepath };
|
||||
async function onSelectFilesToAdd(uris: string[]) {
|
||||
const filePromises = uris.map(async (uri) => {
|
||||
const contents = await ideMessenger.ide.readFile(uri);
|
||||
return { contents, filepath: uri };
|
||||
});
|
||||
|
||||
const fileResults = await Promise.all(filePromises);
|
||||
|
|
|
|||
|
|
@ -122,8 +122,13 @@ function CodeSnippetPreview(props: CodeSnippetPreviewProps) {
|
|||
)}
|
||||
<div
|
||||
contentEditable={false}
|
||||
className={`m-0 ${collapsed ? "max-h-[33vh] overflow-hidden" : "overflow-auto"}`}
|
||||
className={`m-0 ${collapsed ? "overflow-hidden" : "overflow-auto"}`}
|
||||
ref={codeBlockRef}
|
||||
style={
|
||||
{
|
||||
// maxHeight: collapsed ? MAX_PREVIEW_HEIGHT : undefined, // Could switch to max-h-[33vh] but then chevron icon shows when height can't change
|
||||
}
|
||||
}
|
||||
>
|
||||
<StyledMarkdownPreview
|
||||
source={`${fence}${getMarkdownLanguageTagForFile(props.item.name)} ${props.item.description}\n${content}\n${fence}`}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import { SymbolWithRange } from "core";
|
||||
import { ctxItemToRifWithContents } from "core/commands/util";
|
||||
import { memo, useContext, useEffect, useMemo, useRef } from "react";
|
||||
import { useRemark } from "react-remark";
|
||||
|
|
@ -27,7 +26,6 @@ import { patchNestedMarkdown } from "./utils/patchNestedMarkdown";
|
|||
import { useAppSelector } from "../../redux/hooks";
|
||||
import { fixDoubleDollarNewLineLatex } from "./utils/fixDoubleDollarLatex";
|
||||
import { selectUIConfig } from "../../redux/slices/configSlice";
|
||||
import { inferResolvedUriFromRelativePath } from "core/util/ideUtils";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
|
||||
const StyledMarkdown = styled.div<{
|
||||
|
|
@ -170,8 +168,6 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
|
|||
}, [allSymbols, previousFileContextItems]);
|
||||
const symbolsRef = useUpdatingRef(previousFileContextItemSymbols);
|
||||
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
const [reactContent, setMarkdownSource] = useRemark({
|
||||
remarkPlugins: [
|
||||
remarkTables,
|
||||
|
|
|
|||
|
|
@ -65,11 +65,7 @@ export class IdeMessenger implements IIdeMessenger {
|
|||
);
|
||||
}
|
||||
|
||||
private _postToIde(
|
||||
messageType: string,
|
||||
data: FromWebviewProtocol[T][0],
|
||||
messageId?: string,
|
||||
) {
|
||||
private _postToIde(messageType: string, data: any, messageId?: string) {
|
||||
if (typeof vscode === "undefined") {
|
||||
if (isJetBrains()) {
|
||||
if (window.postIntellijMessage === undefined) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue