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
1,738 changes: 1,020 additions & 718 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
},
"devDependencies": {
"@lerna/legacy-package-management": "^8.2.4",
"@lvce-editor/eslint-config": "^8.3.0",
"eslint": "10.2.1",
"@lvce-editor/eslint-config": "^13.3.0",
"eslint": "10.5.0",
"lerna": "^8.2.3",
"prettier": "^3.8.3",
"prettier": "^3.8.4",
"typescript": "^6.0.3"
}
}
234 changes: 121 additions & 113 deletions packages/build/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"@babel/preset-typescript": "^7.28.5",
"@lvce-editor/verror": "^1.7.0",
"@lvce-editor/measure-memory": "^3.1.0",
"@rollup/plugin-babel": "^7.0.0",
"@rollup/plugin-babel": "^7.1.0",
"@rollup/plugin-node-resolve": "^16.0.3",
"@types/node": "^22.13.14",
"esbuild": "^0.28.0",
"esbuild": "^0.28.1",
"execa": "^9.6.1",
"rollup": "^4.38.0"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/build/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { join } from 'node:path'
import { root } from './root.ts'

export const threshold = 465_000
export const threshold = 475_000

export const instantiations = 8000

Expand Down
1,247 changes: 671 additions & 576 deletions packages/diff-view/package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions packages/diff-view/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@
}
},
"devDependencies": {
"@jest/globals": "^30.3.0",
"@jest/globals": "^30.4.1",
"@lvce-editor/assert": "^1.5.1",
"@lvce-editor/constants": "^5.11.0",
"@lvce-editor/constants": "^5.14.0",
"@lvce-editor/i18n": "^2.1.0",
"@lvce-editor/rpc": "^6.4.0",
"@lvce-editor/rpc-registry": "^9.22.0",
"@lvce-editor/rpc-registry": "^9.27.0",
"@lvce-editor/verror": "^1.7.0",
"@lvce-editor/viewlet-registry": "^4.1.0",
"@lvce-editor/virtual-dom-worker": "^9.8.0",
"jest": "^30.3.0",
"ts-jest": "^29.4.9"
"@lvce-editor/virtual-dom-worker": "^10.1.0",
"jest": "^30.4.2",
"ts-jest": "^29.4.11"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export const getStackLineHref = (location: string, allowedLinkSchemes: readonly string[]): string => {
const scheme = location.startsWith('/') ? 'file' : location.slice(0, location.indexOf(':'))
if (allowedLinkSchemes.includes(scheme)) {
return scheme === 'file' ? `file://${location.startsWith('file://') ? location.slice('file://'.length) : location}` : location
if (!allowedLinkSchemes.includes(scheme)) {
return '#'
}
return '#'
if (scheme !== 'file') {
return location
}
const filePath = location.startsWith('file://') ? location.slice('file://'.length) : location
return `file://${filePath}`
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { stackLocationRegex } from '../StackLocationRegex/StackLocationRegex.ts'
import { parseStackLocation } from '../StackLocationRegex/StackLocationRegex.ts'

export const getStackLineLocation = (stackLine: string): string => {
const match = stackLine.match(stackLocationRegex)
const match = parseStackLocation(stackLine)
if (!match) {
return ''
}
const [, location] = match
return location
return match.location
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { stackLocationRegex } from '../StackLocationRegex/StackLocationRegex.ts'
import { parseStackLocation } from '../StackLocationRegex/StackLocationRegex.ts'

export const getStackLinePrefix = (stackLine: string): string => {
const match = stackLine.match(stackLocationRegex)
const match = parseStackLocation(stackLine)
if (!match) {
return stackLine
}
return stackLine.slice(0, stackLine.length - match[0].length).replace(/\($/, '')
return stackLine.slice(0, stackLine.length - match.text.length).replace(/\($/, '')
}
Original file line number Diff line number Diff line change
@@ -1 +1,83 @@
export const stackLocationRegex = /((?:[a-zA-Z][a-zA-Z0-9+.-]*:\/\/|\/)[^\s)]+):(\d+):(\d+)\)?$/
export interface StackLocationMatch {
readonly location: string
readonly text: string
}

const isSchemeCharacter = (char: string): boolean => {
return (char >= 'a' && char <= 'z') || (char >= 'A' && char <= 'Z') || (char >= '0' && char <= '9') || char === '+' || char === '.' || char === '-'
}

const isSchemeStart = (char: string): boolean => {
return (char >= 'a' && char <= 'z') || (char >= 'A' && char <= 'Z')
}

const isLocationBoundary = (stackLine: string, index: number): boolean => {
return index === 0 || stackLine[index - 1] === '(' || /\s/.test(stackLine[index - 1])
}

const getSchemeLocationStart = (stackLine: string, locationEnd: number): number => {
const schemeSeparator = stackLine.lastIndexOf('://', locationEnd)
if (schemeSeparator === -1) {
return -1
}
let start = schemeSeparator - 1
while (start >= 0 && isSchemeCharacter(stackLine[start])) {
start--
}
start++
if (!isSchemeStart(stackLine[start]) || !isLocationBoundary(stackLine, start)) {
return -1
}
return start
}

const getFileLocationStart = (stackLine: string, locationEnd: number): number => {
for (let index = locationEnd - 1; index >= 0; index--) {
if (stackLine[index] === '/' && isLocationBoundary(stackLine, index)) {
return index
}
}
return -1
}

const getLocationStart = (stackLine: string, locationEnd: number): number => {
const schemeStart = getSchemeLocationStart(stackLine, locationEnd)
if (schemeStart !== -1) {
return schemeStart
}
return getFileLocationStart(stackLine, locationEnd)
}

const isDigits = (text: string): boolean => {
for (const char of text) {
if (char < '0' || char > '9') {
return false
}
}
return text.length > 0
}

export const parseStackLocation = (stackLine: string): StackLocationMatch | undefined => {
const textEnd = stackLine.endsWith(')') ? stackLine.length - 1 : stackLine.length
const columnSeparator = stackLine.lastIndexOf(':', textEnd - 1)
if (columnSeparator === -1) {
return undefined
}
const lineSeparator = stackLine.lastIndexOf(':', columnSeparator - 1)
if (lineSeparator === -1) {
return undefined
}
const line = stackLine.slice(lineSeparator + 1, columnSeparator)
const column = stackLine.slice(columnSeparator + 1, textEnd)
if (!isDigits(line) || !isDigits(column)) {
return undefined
}
const locationStart = getLocationStart(stackLine, lineSeparator)
if (locationStart === -1) {
return undefined
}
return {
location: stackLine.slice(locationStart, lineSeparator),
text: stackLine.slice(locationStart),
}
}
131 changes: 85 additions & 46 deletions packages/diff-view/src/parts/GetInlineDiffRows/GetInlineDiffRows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,81 @@ const findLookAheadMatch = (lines: readonly string[], startIndex: number, needle
return -1
}

const getContextRow = (lineNumberLeft: number, lineNumberRight: number, text: string): InlineDiffRow => ({
lineNumberLeft,
lineNumberRight,
text,
type: InlineDiffRowType.Context,
})

const getDeletionRow = (lineNumberLeft: number, text: string): InlineDiffRow => ({
lineNumberLeft,
lineNumberRight: null,
text,
type: InlineDiffRowType.Deletion,
})

const getInsertionRow = (lineNumberRight: number, text: string): InlineDiffRow => ({
lineNumberLeft: null,
lineNumberRight,
text,
type: InlineDiffRowType.Insertion,
})

const getDeletionRows = (lines: readonly string[], startIndex: number, endIndex: number, startLineNumber: number): readonly InlineDiffRow[] => {
const rows: InlineDiffRow[] = []
for (let index = startIndex; index < endIndex; index++) {
rows.push(getDeletionRow(startLineNumber + index - startIndex, lines[index]))
}
return rows
}

const getInsertionRows = (lines: readonly string[], startIndex: number, endIndex: number, startLineNumber: number): readonly InlineDiffRow[] => {
const rows: InlineDiffRow[] = []
for (let index = startIndex; index < endIndex; index++) {
rows.push(getInsertionRow(startLineNumber + index - startIndex, lines[index]))
}
return rows
}

interface LookAheadRows {
readonly leftCount: number
readonly rightCount: number
readonly rows: readonly InlineDiffRow[]
}

const getLookAheadRows = (
leftLines: readonly string[],
rightLines: readonly string[],
leftIndex: number,
rightIndex: number,
leftLineNumber: number,
rightLineNumber: number,
): LookAheadRows | undefined => {
const leftLine = leftLines[leftIndex]
const rightLine = rightLines[rightIndex]
const leftMatch = findLookAheadMatch(leftLines, leftIndex + 1, rightLine)
const rightMatch = findLookAheadMatch(rightLines, rightIndex + 1, leftLine)

if (leftMatch !== -1 && (rightMatch === -1 || leftMatch - leftIndex <= rightMatch - rightIndex)) {
return {
leftCount: leftMatch - leftIndex,
rightCount: 0,
rows: getDeletionRows(leftLines, leftIndex, leftMatch, leftLineNumber),
}
}

if (rightMatch !== -1) {
return {
leftCount: 0,
rightCount: rightMatch - rightIndex,
rows: getInsertionRows(rightLines, rightIndex, rightMatch, rightLineNumber),
}
}

return undefined
}

export const getInlineDiffRows = (contentLeft: string, contentRight: string): readonly InlineDiffRow[] => {
const leftLines = getLines(contentLeft)
const rightLines = getLines(contentRight)
Expand All @@ -43,12 +118,7 @@ export const getInlineDiffRows = (contentLeft: string, contentRight: string): re
const rightLine = rightLines[rightIndex]

if (leftIndex < leftLines.length && rightIndex < rightLines.length && leftLine === rightLine) {
rows.push({
lineNumberLeft: leftLineNumber,
lineNumberRight: rightLineNumber,
text: leftLine,
type: InlineDiffRowType.Context,
})
rows.push(getContextRow(leftLineNumber, rightLineNumber, leftLine))
leftIndex++
rightIndex++
leftLineNumber++
Expand All @@ -57,56 +127,25 @@ export const getInlineDiffRows = (contentLeft: string, contentRight: string): re
}

if (leftIndex < leftLines.length && rightIndex < rightLines.length) {
const leftMatch = findLookAheadMatch(leftLines, leftIndex + 1, rightLine)
const rightMatch = findLookAheadMatch(rightLines, rightIndex + 1, leftLine)

if (leftMatch !== -1 && (rightMatch === -1 || leftMatch - leftIndex <= rightMatch - rightIndex)) {
while (leftIndex < leftMatch) {
rows.push({
lineNumberLeft: leftLineNumber,
lineNumberRight: null,
text: leftLines[leftIndex],
type: InlineDiffRowType.Deletion,
})
leftIndex++
leftLineNumber++
}
continue
}

if (rightMatch !== -1) {
while (rightIndex < rightMatch) {
rows.push({
lineNumberLeft: null,
lineNumberRight: rightLineNumber,
text: rightLines[rightIndex],
type: InlineDiffRowType.Insertion,
})
rightIndex++
rightLineNumber++
}
const lookAheadRows = getLookAheadRows(leftLines, rightLines, leftIndex, rightIndex, leftLineNumber, rightLineNumber)
if (lookAheadRows) {
rows.push(...lookAheadRows.rows)
leftIndex += lookAheadRows.leftCount
leftLineNumber += lookAheadRows.leftCount
rightIndex += lookAheadRows.rightCount
rightLineNumber += lookAheadRows.rightCount
continue
}
}

if (leftIndex < leftLines.length) {
rows.push({
lineNumberLeft: leftLineNumber,
lineNumberRight: null,
text: leftLines[leftIndex],
type: InlineDiffRowType.Deletion,
})
rows.push(getDeletionRow(leftLineNumber, leftLines[leftIndex]))
leftIndex++
leftLineNumber++
}

if (rightIndex < rightLines.length) {
rows.push({
lineNumberLeft: null,
lineNumberRight: rightLineNumber,
text: rightLines[rightIndex],
type: InlineDiffRowType.Insertion,
})
rows.push(getInsertionRow(rightLineNumber, rightLines[rightIndex]))
rightIndex++
rightLineNumber++
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const getInlineDiffUris = (uri: string): readonly [string, string] => {
}
if (uri.startsWith(diffPrefix)) {
return parseDiffUris(uri.slice(diffPrefix.length))
} else {
return ['', uri]
}
return ['', uri]
}
20 changes: 11 additions & 9 deletions packages/diff-view/src/parts/GetLanguages/GetLanguages.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { ExtensionManagementWorker } from '@lvce-editor/rpc-registry'
import type { SyntaxLanguageContribution } from '../GetSyntaxLanguage/GetSyntaxLanguage.ts'

let cachedAssetDir = ''
let cachedPlatform = -1
let cachedLanguages: readonly SyntaxLanguageContribution[] = []
const languageCache = {
assetDir: '',
languages: [] as readonly SyntaxLanguageContribution[],
platform: -1,
}

export const getLanguages = async (platform: number, assetDir: string): Promise<readonly SyntaxLanguageContribution[]> => {
if (cachedPlatform === platform && cachedAssetDir === assetDir) {
return cachedLanguages
if (languageCache.platform === platform && languageCache.assetDir === assetDir) {
return languageCache.languages
}
try {
const languages = await ExtensionManagementWorker.invoke('Extensions.getLanguages', platform, assetDir)
if (!Array.isArray(languages)) {
return []
}
cachedPlatform = platform
cachedAssetDir = assetDir
cachedLanguages = languages as readonly SyntaxLanguageContribution[]
return cachedLanguages
languageCache.platform = platform
languageCache.assetDir = assetDir
languageCache.languages = languages as readonly SyntaxLanguageContribution[]
return languageCache.languages
} catch {
return []
}
Expand Down
Loading