Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show type check result while typing arguments #8

Merged
merged 7 commits into from
Feb 4, 2024
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
2 changes: 1 addition & 1 deletion aftman.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

# To add a new tool, add an entry to this table.
[tools]
rojo = "rojo-rbx/[email protected]-rc3"
rojo = "rojo-rbx/[email protected]"
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@biomejs/biome": "1.4.1",
"@rbxts/compiler-types": "2.2.0-types.0",
"@rbxts/midori": "^0.1.3",
"@rbxts/types": "^1.0.738",
"@rbxts/types": "^1.0.747",
"roblox-ts": "^2.2.0",
"typescript": "=5.2"
},
Expand All @@ -48,8 +48,8 @@
"@rbxts/ripple": "^0.7.1",
"@rbxts/roact": "npm:@rbxts/react-ts@^1.0.1",
"@rbxts/rust-classes": "^0.12.0",
"@rbxts/services": "^1.5.1",
"@rbxts/services": "^1.5.3",
"@rbxts/sift": "^0.0.8",
"@rbxts/t": "^3.1.0"
"@rbxts/t": "^3.1.1"
}
}
28 changes: 14 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 1 addition & 15 deletions src/client/interface/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ import { AppContext } from "../../types";
import { Layer } from "../components/interface/Layer";
import Terminal from "../components/terminal/Terminal";
import { RootProvider } from "../providers/rootProvider";
import { SuggestionQuery } from "../types";
import { getArgumentSuggestion, getCommandSuggestion } from "./suggestion";

function getSuggestion(query: SuggestionQuery) {
if (query.type === "argument") {
return getArgumentSuggestion(query.commandPath, query.index, query.text);
}

return getCommandSuggestion(query.parentPath, query.text);
}

export function CommanderApp(data: AppContext) {
const root = createRoot(new Instance("Folder"));
Expand All @@ -25,11 +15,7 @@ export function CommanderApp(data: AppContext) {
root.render(
createPortal(
<StrictMode>
<RootProvider
key="root-provider"
value={data}
getSuggestion={getSuggestion}
>
<RootProvider key="root-provider" value={data}>
<Layer key="terminal">
<Terminal key="terminal-layer" />
</Layer>
Expand Down
52 changes: 27 additions & 25 deletions src/client/interface/components/terminal/TerminalTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import { palette } from "../../constants/palette";
import { useRem } from "../../hooks/useRem";
import { useStore } from "../../hooks/useStore";
import { CommanderContext } from "../../providers/commanderProvider";
import { SuggestionContext } from "../../providers/suggestionProvider";
import { selectCommand, selectErrorText, selectVisible } from "../../store/app";
import { selectVisible } from "../../store/app";
import { selectCommand } from "../../store/command";
import { selectCurrentSuggestion } from "../../store/suggestion";
import { selectValid } from "../../store/text";
import { getArgumentNames } from "../../util/argument";
import { Frame } from "../interface/Frame";
import { Padding } from "../interface/Padding";
Expand All @@ -50,19 +52,19 @@ export function TerminalTextField({
const rem = useRem();
const ref = useRef<TextBox>();
const data = useContext(CommanderContext);
const suggestion = useContext(SuggestionContext).suggestion;
const store = useStore();

const appVisible = useSelector(selectVisible);
const currentSuggestion = useSelector(selectCurrentSuggestion);
const [text, setText] = useBinding("");
const [suggestionText, setSuggestionText] = useBinding("");
const [valid, setValid] = useState(false);

const traverseHistory = useCallback((up: boolean) => {
const history = store.getState().app.commandHistory;
const history = store.getState().history.commandHistory;
if (history.isEmpty()) return;

const historyIndex = store.getState().app.commandHistoryIndex;
const historyIndex = store.getState().history.commandHistoryIndex;
if ((up && historyIndex === 0) || (!up && historyIndex === -1)) return;

let newIndex: number;
Expand Down Expand Up @@ -92,32 +94,31 @@ export function TerminalTextField({
}, [appVisible]);

useMountEffect(() => {
let errored = false;
store.subscribe(selectErrorText, (text) => {
errored = text !== undefined;
setValid(!errored);
store.subscribe(selectValid, (valid) => {
setValid(valid);
});

store.subscribe(selectCommand, (command) => {
if (errored) return;
if (!store.getState().text.valid) return;
setValid(command !== undefined);
});
});

useEffect(() => {
if (suggestion === undefined) {
if (currentSuggestion === undefined) {
setSuggestionText("");
return;
}

const parts = store.getState().app.text.parts;
const atNextPart = endsWithSpace(store.getState().app.text.value);
const state = store.getState();
const parts = state.text.parts;
const atNextPart = endsWithSpace(state.text.value);

let newText = getBindingValue(text);
const command = store.getState().app.command;
const argIndex = store.getState().app.argIndex;
const command = state.command.path;
const argIndex = state.command.argIndex;
if (
suggestion.main.type === "argument" &&
currentSuggestion.main.type === "argument" &&
command !== undefined &&
argIndex !== undefined
) {
Expand All @@ -131,14 +132,14 @@ export function TerminalTextField({

newText = `${newText}${argNames[i]} `;
}
} else if (suggestion.main.type === "command") {
} else if (currentSuggestion.main.type === "command") {
const suggestionStartIndex =
(!atNextPart ? parts[parts.size() - 1].size() : 0) + 1;
newText += suggestion.main.title.sub(suggestionStartIndex);
newText += currentSuggestion.main.title.sub(suggestionStartIndex);
}

setSuggestionText(newText);
}, [suggestion]);
}, [currentSuggestion]);

useEventListener(UserInputService.InputBegan, (input) => {
if (ref.current === undefined) return;
Expand All @@ -151,7 +152,8 @@ export function TerminalTextField({

if (input.KeyCode !== Enum.KeyCode.Tab) return;

const commandPath = store.getState().app.command;
const state = store.getState();
const commandPath = state.command.path;
const suggestionTextValue = getBindingValue(suggestionText);

// Handle command suggestions
Expand Down Expand Up @@ -181,21 +183,21 @@ export function TerminalTextField({
// Handle argument suggestions
if (
commandPath === undefined ||
suggestion === undefined ||
suggestion.others.isEmpty()
currentSuggestion === undefined ||
currentSuggestion.others.isEmpty()
)
return;

const argIndex = store.getState().app.argIndex;
const argIndex = state.command.argIndex;
const commandArgs = data.commands.get(commandPath.toString())?.arguments;
if (argIndex === undefined || commandArgs === undefined) return;

let newText = getBindingValue(text);
if (!endsWithSpace(newText)) {
const parts = store.getState().app.text.parts;
const parts = state.text.parts;
newText = newText.sub(0, newText.size() - parts[parts.size() - 1].size());
}
newText += suggestion.others[0];
newText += currentSuggestion.others[0];

if (argIndex < commandArgs.size() - 1) {
newText += " ";
Expand Down
Loading
Loading