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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules
.env
.build
.yarn-lock
.package-lock
yarn.lock
package.lock
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
CodeBoost is a code runner that allows you to refactor and run your code in one convenient location. With CodeBoost, you can improve the quality and readability of your code with just a few clicks, and then run it to see the results instantly.

# Features
- <b>Code refactoring:</b> CodeBoost makes it easy to refactor your code by suggesting changes that will improve its quality, readability, and performance. You can choose from a variety of refactorings, including renaming variables, extracting methods, and removing duplicate code.
- <b>Code refactoring:</b> CodeBoost makes it easy to refactor your code by suggesting changes that will improve its quality, readability, and performance. You can choose to refactor the whole code or part of code by selecting the code snippet and refactor that part.
- <b>Code running</b>: CodeBoost allows you to run your code directly from the editor, without having to switch to a different tool or environment. You can run your code as many times as you like, with different input values, and see the output and any errors or exceptions that occur.

# Languages supported
Expand Down
2 changes: 2 additions & 0 deletions src/Components/CodeEditor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { EditorView } from "@codemirror/view";
import { mapLanguages } from "./utils";

const CodeEditor = ({
editorRef,
selectedLanguage,
value,
onChange,
Expand Down Expand Up @@ -39,6 +40,7 @@ const CodeEditor = ({
return (
<>
<CodeMirror
ref={editorRef}
value={value}
extensions={extensions}
theme={sublime}
Expand Down
11 changes: 9 additions & 2 deletions src/Components/Main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import CodeActions from "./CodeActions";

const Main = () => {
const outputRef = useRef(null);
const editorRef = useRef(null);

const [selectedLanguage, setSelectedLanguage] = useState(LANGUAGE_OPTIONS[0]);
const [value, setValue] = useState(selectedLanguage?.stub);
Expand Down Expand Up @@ -82,14 +83,19 @@ const Main = () => {
const refactorCode = async () => {
try {
setIsLoading(true);
const cursorSelection = editorRef.current.view.state.selection.main;
const startRange = cursorSelection.from;
const endRange = cursorSelection.to;
const selectedValue =
startRange !== endRange ? value.substring(startRange, endRange) : value;

const { data: chatGptOutput } = await getRefactoredCode({
model: "gpt-3.5-turbo",
messages: [{ role: "user", content: `Refactor code ${value}` }],
messages: [{ role: "user", content: `Refactor code snippet ${selectedValue}` }],
});

const refactoredCode = chatGptOutput.choices[0].message.content;
setValue(refactoredCode);
setValue((prevValue) => prevValue.replace(selectedValue, refactoredCode));
} catch (err) {
console.log(err);
} finally {
Expand Down Expand Up @@ -117,6 +123,7 @@ const Main = () => {
</div>
<div className="editor-height mt-5">
<CodeEditor
editorRef={editorRef}
selectedLanguage={selectedLanguage?.title.toLowerCase()}
value={value}
onChange={setValue}
Expand Down