mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
Merge pull request #28760 from overleaf/dp-hackathon-knip
Add Knip and remove a bunch of unused code GitOrigin-RevId: 42ab99fc65973c883d2361e0027e7181767e714e
This commit is contained in:
@@ -44,7 +44,6 @@ function filterByType(type: 'file' | 'doc' | 'folder') {
|
||||
}
|
||||
|
||||
export const filterFiles = filterByType('file')
|
||||
export const filterDocs = filterByType('doc')
|
||||
export const filterFolders = filterByType('folder')
|
||||
|
||||
const IMAGE_FILE_EXTENSIONS = ['png', 'jpg', 'jpeg', 'pdf']
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
import { SubView } from '../../../../../types/review-panel/review-panel'
|
||||
|
||||
export const isCurrentFileView = (view: SubView) => view === 'cur_file'
|
||||
export const isOverviewView = (view: SubView) => view === 'overview'
|
||||
@@ -1,68 +1,8 @@
|
||||
import { ensureSyntaxTree, syntaxTree } from '@codemirror/language'
|
||||
import { syntaxTree } from '@codemirror/language'
|
||||
import { EditorSelection, EditorState, SelectionRange } from '@codemirror/state'
|
||||
import { SyntaxNode, Tree } from '@lezer/common'
|
||||
import { ListEnvironment } from '../../lezer-latex/latex.terms.mjs'
|
||||
|
||||
const HUNDRED_MS = 100
|
||||
|
||||
export type AncestorItem = {
|
||||
node: SyntaxNode
|
||||
label: string
|
||||
type?: string
|
||||
from: number
|
||||
to: number
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stack of 'ancestor' nodes at the given position.
|
||||
* The first element is the most distant ancestor, while the last element
|
||||
* is the node at the position.
|
||||
*/
|
||||
export function getAncestorStack(
|
||||
state: EditorState,
|
||||
pos: number
|
||||
): AncestorItem[] | null {
|
||||
const tree = ensureSyntaxTree(state, pos, HUNDRED_MS)
|
||||
|
||||
if (!tree) {
|
||||
return null
|
||||
}
|
||||
|
||||
const stack: AncestorItem[] = []
|
||||
const selectedNode = tree.resolve(pos, 0)
|
||||
|
||||
let node: SyntaxNode | null = selectedNode
|
||||
while (node) {
|
||||
const name = node.type.name
|
||||
switch (name) {
|
||||
case 'Environment':
|
||||
{
|
||||
const data: AncestorItem = {
|
||||
node,
|
||||
label: name,
|
||||
from: node.from,
|
||||
to: node.to,
|
||||
}
|
||||
|
||||
const child = node.getChild('EnvNameGroup')
|
||||
if (child) {
|
||||
data.type = state.doc.sliceString(child.from + 1, child.to - 1)
|
||||
}
|
||||
stack.push(data)
|
||||
}
|
||||
break
|
||||
|
||||
default:
|
||||
stack.push({ node, label: name, from: node.from, to: node.to })
|
||||
break
|
||||
}
|
||||
|
||||
node = node.parent
|
||||
}
|
||||
|
||||
return stack.reverse()
|
||||
}
|
||||
|
||||
export const wrappedNodeOfType = (
|
||||
state: EditorState,
|
||||
range: SelectionRange,
|
||||
|
||||
@@ -1,29 +1,9 @@
|
||||
import { ensureSyntaxTree } from '@codemirror/language'
|
||||
import { EditorState } from '@codemirror/state'
|
||||
import { IterMode, SyntaxNode, SyntaxNodeRef, Tree } from '@lezer/common'
|
||||
import { SyntaxNode } from '@lezer/common'
|
||||
|
||||
const HUNDRED_MS = 100
|
||||
|
||||
export function iterateDescendantsOf(
|
||||
tree: Tree,
|
||||
ancestors: (string | number)[],
|
||||
spec: {
|
||||
enter(node: SyntaxNodeRef): boolean | void
|
||||
leave?(node: SyntaxNodeRef): void
|
||||
from?: number | undefined
|
||||
to?: number | undefined
|
||||
mode?: IterMode | undefined
|
||||
}
|
||||
) {
|
||||
const filteredEnter = (node: SyntaxNodeRef): boolean | void => {
|
||||
if (!ancestors.some(x => node.type.is(x))) {
|
||||
return false
|
||||
}
|
||||
return spec.enter(node)
|
||||
}
|
||||
tree.iterate({ ...spec, enter: filteredEnter })
|
||||
}
|
||||
|
||||
export const previousSiblingIs = (
|
||||
state: EditorState,
|
||||
pos: number,
|
||||
@@ -38,20 +18,6 @@ export const previousSiblingIs = (
|
||||
return previousNode?.type.name === expectedName
|
||||
}
|
||||
|
||||
export const nextSiblingIs = (
|
||||
state: EditorState,
|
||||
pos: number,
|
||||
expectedName: string
|
||||
): boolean | null => {
|
||||
const tree = ensureSyntaxTree(state, pos, HUNDRED_MS)
|
||||
if (!tree) {
|
||||
return null
|
||||
}
|
||||
const thisNode = tree.resolve(pos)
|
||||
const previousNode = thisNode?.nextSibling
|
||||
return previousNode?.type.name === expectedName
|
||||
}
|
||||
|
||||
export const getOptionalArgumentText = (
|
||||
state: EditorState,
|
||||
optionalArgumentNode: SyntaxNode
|
||||
|
||||
@@ -297,11 +297,3 @@ export function parseFigureData(
|
||||
graphicsCommandArguments,
|
||||
})
|
||||
}
|
||||
|
||||
export const getBeginEnvSuffix = (state: EditorState, node: SyntaxNode) => {
|
||||
const argumentNode = node
|
||||
.getChild('OptionalArgument')
|
||||
?.getChild('ShortOptionalArg')
|
||||
|
||||
return argumentNode && state.sliceDoc(argumentNode.from, argumentNode.to)
|
||||
}
|
||||
|
||||
@@ -6,11 +6,7 @@ export type {
|
||||
Outline,
|
||||
} from './tree-operations/outline'
|
||||
|
||||
export {
|
||||
iterateDescendantsOf,
|
||||
previousSiblingIs,
|
||||
nextSiblingIs,
|
||||
} from './tree-operations/common'
|
||||
export { previousSiblingIs } from './tree-operations/common'
|
||||
|
||||
export {
|
||||
cursorIsAtBeginEnvironment,
|
||||
@@ -19,7 +15,6 @@ export {
|
||||
} from './tree-operations/environments'
|
||||
|
||||
export {
|
||||
getAncestorStack,
|
||||
ancestorNodeOfType,
|
||||
ancestorOfNodeWithType,
|
||||
getBibkeyArgumentNode,
|
||||
|
||||
Reference in New Issue
Block a user