From c31d7169e651d9fd37cdcaf4d69859d55c5a5e49 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 12 Jul 2023 15:19:57 -0700 Subject: purging more --- extension/react-app/src/TestPage.tsx | 33 --- extension/react-app/src/assets/Hubot-Sans.woff2 | Bin 165932 -> 0 bytes extension/react-app/src/assets/Mona-Sans.woff2 | Bin 133748 -> 0 bytes extension/react-app/src/assets/react.svg | 1 - .../react-app/src/components/CodeMultiselect.tsx | 276 --------------------- extension/react-app/src/highlight/dark.min.css | 53 ---- extension/react-app/src/util/api.ts | 43 ---- extension/react-app/src/util/editCache.ts | 89 ------- extension/react-app/src/util/index.ts | 27 -- 9 files changed, 522 deletions(-) delete mode 100644 extension/react-app/src/TestPage.tsx delete mode 100644 extension/react-app/src/assets/Hubot-Sans.woff2 delete mode 100644 extension/react-app/src/assets/Mona-Sans.woff2 delete mode 100644 extension/react-app/src/assets/react.svg delete mode 100644 extension/react-app/src/components/CodeMultiselect.tsx delete mode 100644 extension/react-app/src/highlight/dark.min.css delete mode 100644 extension/react-app/src/util/api.ts delete mode 100644 extension/react-app/src/util/editCache.ts delete mode 100644 extension/react-app/src/util/index.ts (limited to 'extension/react-app/src') diff --git a/extension/react-app/src/TestPage.tsx b/extension/react-app/src/TestPage.tsx deleted file mode 100644 index d104980b..00000000 --- a/extension/react-app/src/TestPage.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import React from "react"; -import styled from "styled-components"; - -const SideBySideDiv = styled.div` - display: grid; - grid-template-columns: 1fr 1fr; - grid-template-rows: 1fr; - grid-template-areas: "left right"; -`; - -const LeftDiv = styled.div` - grid-area: left; -`; - -const RightDiv = styled.div` - grid-area: right; -`; - -function TestPage() { - return ( -
-

Continue

- - -

Left

-
- -

Right

-
-
-
- ); -} diff --git a/extension/react-app/src/assets/Hubot-Sans.woff2 b/extension/react-app/src/assets/Hubot-Sans.woff2 deleted file mode 100644 index 5089fc47..00000000 Binary files a/extension/react-app/src/assets/Hubot-Sans.woff2 and /dev/null differ diff --git a/extension/react-app/src/assets/Mona-Sans.woff2 b/extension/react-app/src/assets/Mona-Sans.woff2 deleted file mode 100644 index 8208a500..00000000 Binary files a/extension/react-app/src/assets/Mona-Sans.woff2 and /dev/null differ diff --git a/extension/react-app/src/assets/react.svg b/extension/react-app/src/assets/react.svg deleted file mode 100644 index 6c87de9b..00000000 --- a/extension/react-app/src/assets/react.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/extension/react-app/src/components/CodeMultiselect.tsx b/extension/react-app/src/components/CodeMultiselect.tsx deleted file mode 100644 index c0ab9400..00000000 --- a/extension/react-app/src/components/CodeMultiselect.tsx +++ /dev/null @@ -1,276 +0,0 @@ -import React, { useEffect, useState } from "react"; -import styled from "styled-components"; -import { Button, buttonColor, defaultBorderRadius, secondaryDark } from "."; -import { useSelector } from "react-redux"; -import { - selectDebugContext, - selectAllRangesInFiles, - selectRangesMask, -} from "../redux/selectors/debugContextSelectors"; -import "../highlight/dark.min.css"; -import hljs from "highlight.js"; -import { postVscMessage } from "../vscode"; -import { RootStore } from "../redux/store"; -import { useDispatch } from "react-redux"; -import { - addRangeInFile, - deleteRangeInFileAt, - toggleSelectionAt, - updateFileSystem, -} from "../redux/slices/debugContexSlice"; -import { RangeInFile } from "../../../src/client"; -import { readRangeInVirtualFileSystem } from "../util"; - -//#region Styled Components - -const MultiSelectContainer = styled.div` - border-radius: ${defaultBorderRadius}; - padding: 4px; - display: flex; - flex-direction: column; - gap: 4px; -`; - -const MultiSelectHeader = styled.div` - display: flex; - justify-content: space-between; - align-items: left; - border-bottom: 1px solid gray; - padding-left: 4px; - padding-right: 4px; - & p { - overflow-wrap: break-word; - word-wrap: break-word; - -ms-wrap-flow: break-word; - overflow: hidden; - } -`; - -const MultiSelectOption = styled.div` - border-radius: ${defaultBorderRadius}; - padding-top: 4px; - cursor: pointer; - background-color: ${secondaryDark}; -`; - -const DeleteSelectedRangeButton = styled(Button)` - align-self: right; - padding: 0px; - margin-top: 0; - aspect-ratio: 1/1; - height: 28px; -`; - -const ToggleHighlightButton = styled(Button)` - display: grid; - justify-content: center; - align-items: center; - grid-template-columns: 30px 1fr; - margin-left: 20px; - order: 1; - width: fit-content; -`; - -//#endregion - -//#region Path Formatting - -const filenameToLanguageMap: any = { - py: "python", - js: "javascript", - ts: "typescript", - html: "html", - css: "css", - java: "java", - c: "c", - cpp: "cpp", - cs: "csharp", - go: "go", - rb: "ruby", - rs: "rust", - swift: "swift", - php: "php", - scala: "scala", - kt: "kotlin", - dart: "dart", - hs: "haskell", - lua: "lua", - pl: "perl", - r: "r", - sql: "sql", - vb: "vb", - xml: "xml", - yaml: "yaml", -}; - -function filenameToLanguage(filename: string): string { - const extension = filename.split(".").pop(); - if (extension === undefined) { - return ""; - } - return filenameToLanguageMap[extension] || ""; -} - -function formatPathRelativeToWorkspace( - path: string, - workspacePath: string | undefined -) { - if (workspacePath === undefined) { - return path; - } - if (path.startsWith(workspacePath)) { - return path.substring(workspacePath.length + 1); - } else { - return path; - } -} - -function formatFileRange( - rangeInFile: RangeInFile, - workspacePath: string | undefined -) { - return `${formatPathRelativeToWorkspace( - rangeInFile.filepath, - workspacePath - )} (lines ${rangeInFile.range.start.line + 1}-${ - rangeInFile.range.end.line + 1 - })`; - // +1 because VS Code Ranges are 0-indexed -} - -//#endregion - -function CodeMultiselect(props: {}) { - // State - const [highlightLocked, setHighlightLocked] = useState(true); - - // Redux - const dispatch = useDispatch(); - const workspacePath = useSelector( - (state: RootStore) => state.config.workspacePath - ); - const debugContext = useSelector(selectDebugContext); - const rangesInFiles = useSelector(selectAllRangesInFiles); - const rangesInFilesMask = useSelector(selectRangesMask); - - useEffect(() => { - let eventListener = (event: any) => { - switch (event.data.type) { - case "highlightedCode": - if (!highlightLocked) { - dispatch( - addRangeInFile({ - rangeInFile: event.data.rangeInFile, - canUpdateLast: true, - }) - ); - dispatch(updateFileSystem(event.data.filesystem)); - } - break; - case "findSuspiciousCode": - for (let c of event.data.codeLocations) { - dispatch(addRangeInFile({ rangeInFile: c, canUpdateLast: false })); - } - dispatch(updateFileSystem(event.data.filesystem)); - postVscMessage("listTenThings", { debugContext }); - break; - } - }; - window.addEventListener("message", eventListener); - return () => window.removeEventListener("message", eventListener); - }, [debugContext, highlightLocked]); - - useEffect(() => { - hljs.highlightAll(); - }, [rangesInFiles]); - - return ( - - {rangesInFiles.map((range: RangeInFile, index: number) => { - return ( - { - dispatch(toggleSelectionAt(index)); - }} - > - -

- {formatFileRange(range, workspacePath)} -

- dispatch(deleteRangeInFileAt(index))} - > - x - -
-
-              
-                {readRangeInVirtualFileSystem(range, debugContext.filesystem)}
-              
-            
-
- ); - })} - {rangesInFiles.length === 0 && ( - <> -

Highlight relevant code in the editor.

- - )} - { - setHighlightLocked(!highlightLocked); - }} - > - {highlightLocked ? ( - <> - - - {" "} - Enable Highlight - - ) : ( - <> - - - {" "} - Disable Highlight - - )} - -
- ); -} - -export default CodeMultiselect; diff --git a/extension/react-app/src/highlight/dark.min.css b/extension/react-app/src/highlight/dark.min.css deleted file mode 100644 index 9268d7c9..00000000 --- a/extension/react-app/src/highlight/dark.min.css +++ /dev/null @@ -1,53 +0,0 @@ -pre code.hljs { - display: block; - overflow-x: auto; - padding: 1em; -} -code.hljs { - padding: 3px 5px; -} -.hljs { - color: #ddd; - background: #252526; -} -.hljs-keyword, -.hljs-link, -.hljs-literal, -.hljs-section, -.hljs-selector-tag { - color: #fff; -} -.hljs-addition, -.hljs-attribute, -.hljs-built_in, -.hljs-bullet, -.hljs-name, -.hljs-string, -.hljs-symbol, -.hljs-template-tag, -.hljs-template-variable, -.hljs-title, -.hljs-type, -.hljs-variable { - color: #d88; -} -.hljs-comment, -.hljs-deletion, -.hljs-meta, -.hljs-quote { - color: #979797; -} -.hljs-doctag, -.hljs-keyword, -.hljs-literal, -.hljs-name, -.hljs-section, -.hljs-selector-tag, -.hljs-strong, -.hljs-title, -.hljs-type { - font-weight: 700; -} -.hljs-emphasis { - font-style: italic; -} diff --git a/extension/react-app/src/util/api.ts b/extension/react-app/src/util/api.ts deleted file mode 100644 index bdec1d20..00000000 --- a/extension/react-app/src/util/api.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { - Configuration, - DebugApi, - UnittestApi, - ChatApi, -} from "../../../src/client"; -import { useSelector } from "react-redux"; -import { useEffect, useState } from "react"; -import { RootStore } from "../redux/store"; - -export function useApi() { - const apiUrl = useSelector((state: RootStore) => state.config.apiUrl); - const vscMachineId = useSelector( - (state: RootStore) => state.config.vscMachineId - ); - const [debugApi, setDebugApi] = useState(); - const [unittestApi, setUnittestApi] = useState(); - const [chatApi, setChatApi] = useState(); - - useEffect(() => { - if (apiUrl && vscMachineId) { - let config = new Configuration({ - basePath: apiUrl, - fetchApi: fetch, - middleware: [ - { - pre: async (context) => { - context.init.headers = { - ...context.init.headers, - "x-vsc-machine-id": vscMachineId, - }; - }, - }, - ], - }); - setDebugApi(new DebugApi(config)); - setUnittestApi(new UnittestApi(config)); - setChatApi(new ChatApi(config)); - } - }, [apiUrl, vscMachineId]); - - return { debugApi, unittestApi, chatApi }; -} diff --git a/extension/react-app/src/util/editCache.ts b/extension/react-app/src/util/editCache.ts deleted file mode 100644 index b8071127..00000000 --- a/extension/react-app/src/util/editCache.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { useApi } from "../util/api"; -import { FileEdit, SerializedDebugContext } from "../../../src/client"; -import { useCallback, useEffect, useState } from "react"; - -export function useEditCache() { - const { debugApi } = useApi(); - - const fetchNewEdit = useCallback( - async (debugContext: SerializedDebugContext) => { - return ( - await debugApi?.editEndpointDebugEditPost({ - serializedDebugContext: debugContext, - }) - )?.completion; - }, - [debugApi] - ); - - const [editCache, setEditCache] = useState(new EditCache(fetchNewEdit)); - - useEffect(() => { - setEditCache(new EditCache(fetchNewEdit)); - }, [fetchNewEdit]); - - return editCache; -} - -/** - * Stores preloaded edits, invalidating based off of debug context changes - */ -class EditCache { - private _lastDebugContext: SerializedDebugContext | undefined; - private _cachedEdits: FileEdit[] | undefined; - private _fetchNewEdit: ( - debugContext: SerializedDebugContext - ) => Promise; - private _debounceTimer: NodeJS.Timeout | undefined; - - private _debugContextChanged(debugContext: SerializedDebugContext): boolean { - if (!this._lastDebugContext) { - return true; - } - - return ( - JSON.stringify(this._lastDebugContext) !== JSON.stringify(debugContext) - ); - } - - private _debugContextComplete(debugContext: SerializedDebugContext): boolean { - return debugContext.rangesInFiles.length > 0; - } - - public async preloadEdit(debugContext: SerializedDebugContext) { - if (this._debounceTimer) { - clearTimeout(this._debounceTimer); - } - if ( - this._debugContextComplete(debugContext) && - this._debugContextChanged(debugContext) - ) { - this._debounceTimer = setTimeout(async () => { - console.log("Preloading edits"); - this._cachedEdits = await this._fetchNewEdit(debugContext); - this._lastDebugContext = debugContext; - }, 200); - } - } - - public async getEdit( - debugContext: SerializedDebugContext - ): Promise { - if (this._debugContextChanged(debugContext)) { - console.log("Cache miss"); - this._cachedEdits = await this._fetchNewEdit(debugContext); - } else { - console.log("Cache hit"); - } - - return this._cachedEdits!; - } - - constructor( - fetchNewEdit: ( - debugContext: SerializedDebugContext - ) => Promise - ) { - this._fetchNewEdit = fetchNewEdit; - } -} diff --git a/extension/react-app/src/util/index.ts b/extension/react-app/src/util/index.ts deleted file mode 100644 index 458f9d95..00000000 --- a/extension/react-app/src/util/index.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { RangeInFile } from "../../../src/client"; - -export function readRangeInVirtualFileSystem( - rangeInFile: RangeInFile, - filesystem: { [filepath: string]: string } -): string | undefined { - const range = rangeInFile.range; - - let data = filesystem[rangeInFile.filepath]; - if (data === undefined) { - console.log("File not found"); - return undefined; - } else { - let lines = data.toString().split("\n"); - if (range.start.line === range.end.line) { - return lines[rangeInFile.range.start.line].slice( - rangeInFile.range.start.character, - rangeInFile.range.end.character - ); - } else { - let firstLine = lines[range.start.line].slice(range.start.character); - let lastLine = lines[range.end.line].slice(0, range.end.character); - let middleLines = lines.slice(range.start.line + 1, range.end.line); - return [firstLine, ...middleLines, lastLine].join("\n"); - } - } -} -- cgit v1.2.3-70-g09d2