Skip to content

Commit

Permalink
fix: adding normalize base on os
Browse files Browse the repository at this point in the history
  • Loading branch information
Sma1lboy committed Nov 9, 2024
1 parent a7f65b5 commit bf89bd2
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions ee/tabby-ui/app/(dashboard)/activities/components/activity.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use client'

import os from 'os'
import path from 'path'
import React from 'react'
import dynamic from 'next/dynamic'
import { capitalize } from 'lodash-es'
Expand Down Expand Up @@ -308,7 +310,45 @@ function ActivityRow({
let payloadJson
try {
payloadJson = JSON.parse(activity.payload) as {
[key: string]: { language?: string }
completion?: {
segments?: {
filepath?: string
declarations?: Array<{
filepath?: string
body?: string
}>
}
}
}

const isWindows = os.platform() === 'win32'
const separator = isWindows ? '\\' : '/'

const hasDeclarations = Boolean(
payloadJson?.completion?.segments?.declarations?.length
)
const hasSegmentPath = Boolean(payloadJson?.completion?.segments?.filepath)

if (hasDeclarations || hasSegmentPath) {
if (hasSegmentPath) {
payloadJson.completion!.segments!.filepath = path
.normalize(payloadJson.completion!.segments!.filepath!)
.replace(/[/\\]/g, separator)
}

if (hasDeclarations) {
const normalizedDeclarations =
payloadJson.completion!.segments?.declarations!.map(declaration => ({
...declaration,
filepath: declaration.filepath
? path
.normalize(declaration.filepath)
.replace(/[/\\]/g, separator)
: declaration.filepath
}))

payloadJson.completion!.segments!.declarations = normalizedDeclarations
}
}
} catch (error: any) {
if (error?.message) {
Expand All @@ -324,7 +364,6 @@ function ActivityRow({
tooltip = 'Code completion supplied'
break
}

case EventKind.Dismiss: {
tooltip = 'Code completion viewed but not used'
break
Expand All @@ -342,6 +381,7 @@ function ActivityRow({
let displayUser = activity.userId
const user = members.find(user => user.id === activity.userId)
if (user) displayUser = user.name || user.email

return (
<>
<TableRow
Expand Down

0 comments on commit bf89bd2

Please sign in to comment.