Skip to content

Commit

Permalink
fix build issues
Browse files Browse the repository at this point in the history
  • Loading branch information
milomg committed Jan 9, 2025
1 parent 2511a17 commit e1531f8
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 158 deletions.
5 changes: 0 additions & 5 deletions src/components/EditorBody.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
@click="jumpGoto"
:highlight="gotoHighlights.state.highlight"
/>
<ErrorOverlay
v-if="errorHighlights.state.highlight"
:highlight="errorHighlights.state.highlight"
/>
</div>
</template>

Expand All @@ -27,7 +23,6 @@ import {
} from '../state/state'
import { isSyncing } from '../utils/tabs'
import GotoOverlay from './GotoOverlay.vue'
import ErrorOverlay from './ErrorOverlay.vue'
import { EditorView } from 'codemirror'
import { darkTheme, editorTheme, lightTheme } from '../utils/lezer-mips'
Expand Down
29 changes: 0 additions & 29 deletions src/components/ErrorOverlay.vue

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/ExportModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ async function exportRegions() {
return
}
const result = await backend.assembleRegions(collectLines(current.lines), current.path, state)
const result = await backend.assembleRegions(current.doc, current.path, state)
if (result.regions) {
switch (result.regions.type) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/console/ConsoleTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function makeEditor(): Editor {
)
}
return new Editor(consoleData.console, cursor, () => {}, writable)
return new Editor(consoleData.console, cursor, writable)
}
const state = reactive({
Expand Down
17 changes: 6 additions & 11 deletions src/state/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ import { useSettings } from '../utils/settings'
import { useHighlights } from '../utils/highlights'
import { regular } from '../utils/query/text-size'
import { useStorage } from '../utils/storage'

import { useTabs } from '../utils/tabs'
import { GotoMessage, useGoto } from '../utils/goto'
import { ref } from 'vue'
import { InstructionLine } from '../utils/mips/mips'

export const settings = useSettings()

function widthQuery(text: string) {
return regular.calculate(text).width
}

export const {
tabsState,
tab,
Expand All @@ -23,17 +19,14 @@ export const {
showSettings
} = useTabs()

export const errorHighlights = useHighlights(widthQuery)
export const gotoHighlights = useHighlights<GotoMessage>(widthQuery)
export const errorHighlights = useHighlights()
export const gotoHighlights = useHighlights<GotoMessage>()


const storageResult = useStorage(errorHighlights, tab, onDirty)
const storageResult = useStorage(errorHighlights, tab)

export const { editor, storage, suggestionsStorage } = storageResult

function onDirty(line: number, deleted: number, insert: string[]) {

}
// watch(() => {
// // const cursor = cursorIndex()
// // const line = tab()?.lines[cursor.line]
Expand All @@ -46,3 +39,5 @@ function onDirty(line: number, deleted: number, insert: string[]) {
export const goto = useGoto(gotoHighlights, storageResult)

export const showExportRegionsDialog = ref(false)

export const buildLines = ref(null as InstructionLine[] | null)
4 changes: 0 additions & 4 deletions src/utils/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ export class Editor {
body()

this.redoOperations = []

this.onDirty(line, count, this.data.slice(line, line + insert))
}

public mutateLine(line: number, body: () => void) {
Expand All @@ -205,7 +203,6 @@ export class Editor {
frame.replaced,
...frame.deleted
)
this.onDirty(frame.index, frame.replaced, frame.deleted)

return {
index: frame.index,
Expand Down Expand Up @@ -516,7 +513,6 @@ export class Editor {
constructor(
public data: LineData,
public cursor: SelectionIndex,
public onDirty: DirtyHandler = () => {},
public writable?: (
start: number,
deleted: number,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export async function setupEvents() {
if (current?.uuid === tab.uuid) {
editor.value.replaceAll(modification.data)
} else {
tab.lines = splitLines(modification.data)
tab.doc = modification.data
}

tab.marked = false
Expand Down
46 changes: 0 additions & 46 deletions src/utils/goto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export interface GotoMessage {

export interface GotoInterface {
dismiss(): void
hover(line: number, index: number): void
jump(): SelectionIndex | null
}

Expand Down Expand Up @@ -59,50 +58,6 @@ export function useGoto(
highlights.dismissHighlight()
}

function hover(line: number, index: number) {
highlights.dismissHighlight()

const tokens = storage.storage.highlights[line]
const tokenIndex = findTokenIndex(tokens, index)

if (tokenIndex === null) {
return
}

let match: SearchStorageResult | null

if (cache && cache.line === line && cache.index === tokenIndex) {
match = cache.match
} else {
const token = tokens[tokenIndex]
const text = token.text.trim()

const suggestions = storage.suggestionsStorage()
// I don't care about the performance of this feature too much
match = searchStorage(text, suggestions.body)

cache = {
line: line,
index: tokenIndex,
token,
match,
}
}

if (!match) {
return
}

const message: GotoMessage = {
label: match.suggestion.replace,
line: match.line,
index: match.suggestion.index,
type: match.suggestion.type,
}

highlights.putHighlight(line, tokenIndex, tokens, message)
}

function jump(): SelectionIndex | null {
highlights.dismissHighlight()

Expand All @@ -119,7 +74,6 @@ export function useGoto(

return {
dismiss,
hover,
jump,
}
}
3 changes: 2 additions & 1 deletion src/utils/highlights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type DefaultMessage = string
export interface Highlights<Message = DefaultMessage> {
line: number
offset: number
size: number
message: Message
}

Expand Down Expand Up @@ -35,7 +36,7 @@ export function useHighlights<Message = DefaultMessage>(): HighlightsResult<Mess
index: number,
message: UnwrapRef<Message>
) {
state.highlight = { line, message, offset: index }
state.highlight = { line, message, offset: index, size: 0 }
}

function dismissHighlight() {
Expand Down
59 changes: 0 additions & 59 deletions src/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type ShiftCallback = (line: number, deleted: number, insert: string[]) => void
export function useStorage(
error: HighlightsInterface,
tab: () => EditorTab | null,
dirty: ShiftCallback = () => {}
): StorageResult {
const storage = reactive({
editor: createEditor(),
Expand All @@ -38,17 +37,6 @@ export function useStorage(
// Not reactive.
let suggestions = new SuggestionsStorage()

function highlight(line: number, deleted: number, lines: string[]) {
const result = lines.map((part) => storage.language.highlight(part))

storage.highlights.splice(line, deleted, ...result.map((x) => x.tokens))
suggestions.update(
line,
deleted,
result.map((x) => x.suggestions)
)
}

async function checkSyntax() {
const current = tab()

Expand Down Expand Up @@ -77,59 +65,12 @@ export function useStorage(
}
}

function shiftBreakpoints(line: number, deleted: number, replaced: number) {
const current = tab()

if (!current) {
return
}

const breakpoints = current.breakpoints

let moved = false

for (let a = 0; a < breakpoints.length; a++) {
const bp = breakpoints[a]

if (bp < line + Math.min(deleted, replaced)) {
} else if (deleted > replaced && bp < line + deleted) {
breakpoints.splice(a, 1)
a -= 1
} else {
breakpoints[a] += replaced - deleted
moved = true
}
}

if (moved) {
current.breakpoints = [...new Set(current.breakpoints)]
}
}

function handleDirty(line: number, deleted: number, lines: string[]) {
highlight(line, deleted, lines)

const current = tab()

if (current) {
current.marked = true
}

error.shiftHighlight(line, deleted, lines.length)
shiftBreakpoints(line, deleted, lines.length)

dirty(line, deleted, lines)

dispatchCheckSyntax()
}

function createEditor(): Editor {
const current = tab()

return new Editor(
current?.state.doc.toString().split("\n") ?? ['Nothing yet.'],
{ line: 0, index: 0 },
handleDirty,
current?.writable ?? false ? undefined : () => false // weird
)
}
Expand Down

0 comments on commit e1531f8

Please sign in to comment.