Skip to content

Commit 647656c

Browse files
fix: scaffolding for future language syntax highlighting
1 parent 1f2a58e commit 647656c

File tree

9 files changed

+48
-159
lines changed

9 files changed

+48
-159
lines changed

.vscode/launch.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717
"--extensionDevelopmentPath=${workspaceFolder}/extensions/vscode"
1818
],
1919
"pauseForSourceMap": false,
20-
"outFiles": [
21-
"${workspaceFolder}/extensions/vscode/out/extension.js",
22-
"/Users/natesesti/.continue/config.ts"
23-
],
20+
"outFiles": ["${workspaceFolder}/extensions/vscode/out/extension.js"],
2421
"preLaunchTask": "vscode-extension:build",
2522
"env": {
2623
// "CONTROL_PLANE_ENV": "local"

core/commands/slash/comment.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { SlashCommand } from "../../index.js";
2-
import EditSlashCommand from "./edit.js";
1+
import { SlashCommand } from "../../";
2+
import EditSlashCommand from "./edit";
33

44
const CommentSlashCommand: SlashCommand = {
55
name: "comment",

core/commands/slash/edit.ts

+6-13
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ import {
55
fixCodeLlamaFirstLineIndentation,
66
stopAtLines,
77
streamWithNewLines,
8-
} from "../../autocomplete/lineStream.js";
9-
import { streamLines } from "../../diff/util.js";
10-
import { ContextItemWithId, ILLM, SlashCommand } from "../../index.js";
11-
import { stripImages } from "../../llm/images.js";
8+
} from "../../autocomplete/lineStream";
9+
import { streamLines } from "../../diff/util";
10+
import { ContextItemWithId, ILLM, SlashCommand } from "../../";
11+
import { stripImages } from "../../llm/images";
1212
import {
1313
dedentAndGetCommonWhitespace,
1414
getMarkdownLanguageTagForFile,
15-
} from "../../util/index.js";
15+
} from "../../util/";
1616
import {
1717
contextItemToRangeInFileWithContents,
1818
type RangeInFileWithContents,
19-
} from "../util.js";
19+
} from "../util";
2020

2121
const PROMPT = `Take the file prefix and suffix into account, but only rewrite the code_to_edit as specified in the user_request. The code you write in modified_code_to_edit will replace the code between the code_to_edit tags. Do NOT preface your answer or write anything other than code. The </modified_code_to_edit> tag should be written to indicate the end of the modified code section. Do not ever use nested tags.
2222
@@ -62,13 +62,6 @@ export async function getPromptParts(
6262
) {
6363
const maxTokens = Math.floor(model.contextLength / 2);
6464

65-
const TOKENS_TO_BE_CONSIDERED_LARGE_RANGE = tokenLimit ?? 1200;
66-
// if (model.countTokens(rif.contents) > TOKENS_TO_BE_CONSIDERED_LARGE_RANGE) {
67-
// throw new Error(
68-
// "\n\n**It looks like you've selected a large range to edit, which may take a while to complete. If you'd like to cancel, click the 'X' button above. If you highlight a more specific range, Continue will only edit within it.**"
69-
// );
70-
// }
71-
7265
const BUFFER_FOR_FUNCTIONS = 400;
7366
let totalTokens =
7467
model.countTokens(fullFileContents + PROMPT + input) +

gui/src/components/markdown/CodeBlockToolbar.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ function isTerminalCodeBlock(language: string | undefined, text: string) {
7272

7373
function CodeBlockToolBar(props: CodeBlockToolBarProps) {
7474
const ideMessenger = useContext(IdeMessengerContext);
75-
76-
const [copied, setCopied] = useState(false);
7775
const [applying, setApplying] = useState(false);
7876

7977
return (
@@ -85,8 +83,8 @@ function CodeBlockToolBar(props: CodeBlockToolBarProps) {
8583
isTerminalCodeBlock(props.language, props.text)
8684
? "Run in terminal"
8785
: applying
88-
? "Applying..."
89-
: "Apply to current file"
86+
? "Applying..."
87+
: "Apply to current file"
9088
}
9189
disabled={applying}
9290
style={{ backgroundColor: vscEditorBackground }}

gui/src/components/markdown/PreWithToolbar.tsx

+1-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ function childrenToText(children: any) {
1919
return children.map((child: any) => childToText(child)).join("");
2020
}
2121

22-
function PreWithToolbar(props: {
23-
children: any;
24-
language: string | undefined;
25-
}) {
22+
function PreWithToolbar(props: { children: any; language: string | null }) {
2623
const uiConfig = useUIConfig();
2724
const toolbarBottom = uiConfig?.codeBlockToolbarPosition == "bottom";
2825

gui/src/components/markdown/StyledCode.tsx

-19
This file was deleted.

gui/src/components/markdown/StyledMarkdownPreview.tsx

+36-80
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import React, { memo, useEffect, useState } from "react";
2-
import { useSelector } from "react-redux";
1+
import { memo, useEffect } from "react";
32
import { useRemark } from "react-remark";
4-
import rehypeHighlight from "rehype-highlight";
3+
import rehypeHighlight, { Options } from "rehype-highlight";
54
import rehypeKatex from "rehype-katex";
65
import remarkMath from "remark-math";
76
import styled from "styled-components";
@@ -12,11 +11,11 @@ import {
1211
vscEditorBackground,
1312
vscForeground,
1413
} from "..";
15-
import { RootState } from "../../redux/store";
1614
import { getFontSize } from "../../util";
1715
import LinkableCode from "./LinkableCode";
1816
import PreWithToolbar from "./PreWithToolbar";
1917
import { SyntaxHighlightedPre } from "./SyntaxHighlightedPre";
18+
import { common } from "lowlight";
2019
import "./katex.css";
2120
import "./markdown.css";
2221

@@ -59,19 +58,9 @@ const StyledMarkdown = styled.div<{
5958
}
6059
6160
background-color: ${vscBackground};
62-
font-family:
63-
var(--vscode-font-family),
64-
system-ui,
65-
-apple-system,
66-
BlinkMacSystemFont,
67-
"Segoe UI",
68-
Roboto,
69-
Oxygen,
70-
Ubuntu,
71-
Cantarell,
72-
"Open Sans",
73-
"Helvetica Neue",
74-
sans-serif;
61+
font-family: var(--vscode-font-family), system-ui, -apple-system,
62+
BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell,
63+
"Open Sans", "Helvetica Neue", sans-serif;
7564
font-size: ${(props) => props.fontSize || getFontSize()}px;
7665
padding-left: 8px;
7766
padding-right: 8px;
@@ -92,41 +81,19 @@ interface StyledMarkdownPreviewProps {
9281
scrollLocked?: boolean;
9382
}
9483

95-
const FadeInWords: React.FC = (props: any) => {
96-
const { children, ...otherProps } = props;
84+
const HLJS_LANGUAGE_CLASSNAME_PREFIX = "language-";
9785

98-
const active = useSelector((store: RootState) => store.state.active);
86+
const getLanuageFromClassName = (className: any): string | null => {
87+
if (!className || typeof className !== "string") {
88+
return null;
89+
}
9990

100-
const [textWhenActiveStarted, setTextWhenActiveStarted] = useState(
101-
props.children,
102-
);
91+
const language = className
92+
.split(" ")
93+
.find((word) => word.startsWith(HLJS_LANGUAGE_CLASSNAME_PREFIX))
94+
?.split("-")[1];
10395

104-
useEffect(() => {
105-
if (active) {
106-
setTextWhenActiveStarted(children);
107-
}
108-
}, [active]);
109-
110-
// Split the text into words
111-
const words = children
112-
.map((child) => {
113-
if (typeof child === "string") {
114-
return child.split(" ").map((word, index) => (
115-
<span className="fade-in-span" key={index}>
116-
{word}{" "}
117-
</span>
118-
));
119-
} else {
120-
return <span className="fade-in-span">{child}</span>;
121-
}
122-
})
123-
.flat();
124-
125-
return active && children !== textWhenActiveStarted ? (
126-
<p {...otherProps}>{words}</p>
127-
) : (
128-
<p>{children}</p>
129-
);
96+
return language;
13097
};
13198

13299
const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
@@ -147,7 +114,21 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
147114
};
148115
},
149116
],
150-
rehypePlugins: [rehypeHighlight as any, {}, rehypeKatex as any, {}],
117+
rehypePlugins: [
118+
rehypeKatex as any,
119+
{},
120+
[
121+
rehypeHighlight as any,
122+
{
123+
// Note: This is the default behavior, but leaving this here for scaffolding to
124+
// add unsupported languages in the future.
125+
// https://github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md
126+
languages: { ...common },
127+
} as Options,
128+
129+
,
130+
],
131+
],
151132
rehypeReactOptions: {
152133
components: {
153134
a: ({ node, ...props }) => {
@@ -158,12 +139,12 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
158139
);
159140
},
160141
pre: ({ node, ...preProps }) => {
161-
const language = preProps?.children?.[0]?.props?.className
162-
?.split(" ")
163-
.find((word) => word.startsWith("language-"))
164-
?.split("-")[1];
142+
const childrenClassName = preProps?.children?.[0]?.props?.className;
143+
165144
return props.showCodeBorder ? (
166-
<PreWithToolbar language={language}>
145+
<PreWithToolbar
146+
language={getLanuageFromClassName(childrenClassName)}
147+
>
167148
<SyntaxHighlightedPre {...preProps}></SyntaxHighlightedPre>
168149
</PreWithToolbar>
169150
) : (
@@ -181,31 +162,6 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
181162
<LinkableCode {...codeProps}>{codeProps.children}</LinkableCode>
182163
);
183164
},
184-
// pre: ({ node, ...preProps }) => {
185-
// const codeString =
186-
// preProps.children?.[0]?.props?.children?.[0].trim() || "";
187-
// const monacoEditor = (
188-
// <MonacoCodeBlock
189-
// showBorder={props.showCodeBorder}
190-
// language={
191-
// preProps.children?.[0]?.props?.className?.split("-")[1] ||
192-
// "typescript"
193-
// }
194-
// preProps={preProps}
195-
// codeString={codeString}
196-
// />
197-
// );
198-
// return props.showCodeBorder ? (
199-
// <PreWithToolbar copyvalue={codeString}>
200-
// <SyntaxHighlightedPre {...preProps}></SyntaxHighlightedPre>
201-
// </PreWithToolbar>
202-
// ) : (
203-
// <SyntaxHighlightedPre {...preProps}></SyntaxHighlightedPre>
204-
// );
205-
// },
206-
// p: ({ node, ...props }) => {
207-
// return <FadeInWords {...props}></FadeInWords>;
208-
// },
209165
},
210166
},
211167
});

gui/src/hooks/useChatHandler.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Dispatch } from "@reduxjs/toolkit";
2-
32
import { JSONContent } from "@tiptap/react";
43
import {
54
ChatHistory,

gui/src/pages/gui.tsx

-32
Original file line numberDiff line numberDiff line change
@@ -134,38 +134,6 @@ const NewSessionButton = styled.div`
134134
cursor: pointer;
135135
`;
136136

137-
const ThreadHead = styled.div`
138-
display: flex;
139-
align-items: center;
140-
gap: 6px;
141-
margin: 18px 6px 0 6px;
142-
`;
143-
144-
const THREAD_AVATAR_SIZE = 15;
145-
146-
const ThreadAvatar = styled.div`
147-
width: 24px;
148-
height: 24px;
149-
border-radius: 50%;
150-
background-color: rgba(248, 248, 248, 0.75);
151-
color: #000;
152-
display: flex;
153-
align-items: center;
154-
justify-content: center;
155-
border: 1px solid rgba(136, 136, 136, 0.3);
156-
`;
157-
158-
const ThreadUserTitle = styled.div`
159-
text-transform: capitalize;
160-
font-weight: 500;
161-
margin-bottom: 2px;
162-
`;
163-
164-
const ThreadUserName = styled.div`
165-
font-size: ${getFontSize() - 3}px;
166-
color: ${lightGray};
167-
`;
168-
169137
function fallbackRender({ error, resetErrorBoundary }: any) {
170138
// Call resetErrorBoundary() to reset the error boundary and retry the render.
171139

0 commit comments

Comments
 (0)