CODEBASE: Fix lint errors 2 (#1756)

This commit is contained in:
catloversg
2024-11-07 14:09:11 +07:00
committed by GitHub
parent e3c10e9f0f
commit 36c143b687
48 changed files with 267 additions and 146 deletions
+2 -6
View File
@@ -1,5 +1,4 @@
import React, { useEffect, useRef, useState } from "react";
// @ts-expect-error This library does not have types.
import * as MonacoVim from "monaco-vim";
import type { editor } from "monaco-editor";
type IStandaloneCodeEditor = editor.IStandaloneCodeEditor;
@@ -18,8 +17,7 @@ interface IProps {
}
export function useVimEditor({ editor, vim, onOpenNextTab, onOpenPreviousTab, onSave }: IProps) {
// monaco-vim does not have types, so this is an any
const [vimEditor, setVimEditor] = useState<any>(null);
const [vimEditor, setVimEditor] = useState<ReturnType<typeof MonacoVim.initVimMode> | null>(null);
const statusBarRef = useRef<React.ReactElement | null>(null);
const rerender = useRerender();
@@ -30,7 +28,6 @@ export function useVimEditor({ editor, vim, onOpenNextTab, onOpenPreviousTab, on
useEffect(() => {
// setup monaco-vim
if (vim && editor && !vimEditor) {
// Using try/catch because MonacoVim does not have types.
try {
setVimEditor(MonacoVim.initVimMode(editor, statusBarRef, StatusBar, rerender));
MonacoVim.VimMode.Vim.defineEx("write", "w", function () {
@@ -65,8 +62,7 @@ export function useVimEditor({ editor, vim, onOpenNextTab, onOpenPreviousTab, on
MonacoVim.VimMode.Vim.mapCommand("gT", "action", "prevTabs", {}, { context: "normal" });
editor.focus();
} catch (e) {
console.error("An error occurred while loading monaco-vim:");
console.error(e);
console.error("An error occurred while loading monaco-vim:", e);
}
} else if (!vim) {
// When vim mode is disabled
+2 -1
View File
@@ -2,6 +2,7 @@ import { GetServer } from "../../Server/AllServers";
import { editor, Uri } from "monaco-editor";
import { OpenScript } from "./OpenScript";
import { getFileType, FileType } from "../../utils/ScriptTransformer";
import { throwIfReachable } from "../../utils/helpers/throwIfReachable";
function getServerCode(scripts: OpenScript[], index: number): string | null {
const openScript = scripts[index];
@@ -48,7 +49,7 @@ function makeModel(hostname: string, filename: string, code: string) {
language = "javascript";
break;
default:
throw new Error(`Invalid file type: ${fileType}. Filename: ${filename}.`);
throwIfReachable(fileType);
}
//if somehow a model already exist return it
return editor.getModel(uri) ?? editor.createModel(code, language, uri);