@@ -320,15 +320,52 @@ export function Autocomplete(props: {
320320if ( referenceMatch ( ) ) return [ ]
321321const { lineRange, baseQuery } = extractLineRange ( input . query ?? "" )
322322
323+ const isExplicitPath = baseQuery . startsWith ( "." ) || baseQuery . startsWith ( "/" ) || baseQuery . startsWith ( "~" )
324+ let searchDir = input . location ?. directory || project . data . project . mainDir || project . instance . directory ( ) || process . cwd ( )
325+ let searchQuery = baseQuery
326+
327+ if ( searchDir && isExplicitPath ) {
328+ let expanded = baseQuery
329+ if ( expanded . startsWith ( "~/" ) ) {
330+ expanded = expanded . replace ( / ^ ~ / , process . env . HOME || "" )
331+ }
332+
333+ const resolvedPath = path . resolve ( searchDir , expanded )
334+
335+ if ( baseQuery . endsWith ( "/" ) || baseQuery === "." || baseQuery === ".." ) {
336+ searchDir = resolvedPath
337+ searchQuery = ""
338+ } else {
339+ searchDir = path . dirname ( resolvedPath )
340+ searchQuery = path . basename ( resolvedPath )
341+ }
342+ }
343+
323344// Get files from SDK
324- const result = await sdk . client . v2 . fs . find ( {
325- query : baseQuery ,
326- limit : "20" ,
327- location : {
328- directory : input . location ?. directory ,
329- workspace : input . location ?. workspaceID ?? project . workspace . current ( ) ,
330- } ,
331- } )
345+ let result
346+ if ( isExplicitPath ) {
347+ result = await sdk . client . v2 . fs . list ( {
348+ location : {
349+ directory : searchDir ,
350+ workspace : input . location ?. workspaceID ?? project . workspace . current ( ) ,
351+ } ,
352+ } )
353+
354+ // v2.fs.list returns all entries, so we filter by searchQuery
355+ if ( ! result . error && result . data && searchQuery ) {
356+ const lowerQuery = searchQuery . toLowerCase ( )
357+ result . data . data = result . data . data . filter ( ( item ) => item . path . toLowerCase ( ) . includes ( lowerQuery ) )
358+ }
359+ } else {
360+ result = await sdk . client . v2 . fs . find ( {
361+ query : searchQuery ,
362+ limit : "20" ,
363+ location : {
364+ directory : searchDir ,
365+ workspace : input . location ?. workspaceID ?? project . workspace . current ( ) ,
366+ } ,
367+ } )
368+ }
332369
333370const options : AutocompleteOption [ ] = [ ]
334371
@@ -338,16 +375,38 @@ export function Autocomplete(props: {
338375const width = props . anchor ( ) . width - 4
339376options . push (
340377 ...result . data . data . map ( ( item ) : AutocompleteOption => {
378+ const absolutePath = path . join ( result . data . location . directory , item . path )
379+ let displayPath
380+ if ( baseQuery . startsWith ( "/" ) ) {
381+ displayPath = absolutePath
382+ } else if ( baseQuery . startsWith ( "~" ) ) {
383+ const home = process . env . HOME || ""
384+ if ( home && absolutePath . startsWith ( home ) ) {
385+ displayPath = `~${ absolutePath . slice ( home . length ) } `
386+ } else {
387+ displayPath = absolutePath
388+ }
389+ } else {
390+ const baseDir = input . location ?. directory || project . data . project . mainDir || project . instance . directory ( ) || process . cwd ( )
391+ displayPath = path . relative ( baseDir , absolutePath )
392+
393+ if ( isExplicitPath && baseQuery . startsWith ( "./" ) && ! displayPath . startsWith ( "." ) ) {
394+ displayPath = `./${ displayPath } `
395+ }
396+ }
397+
398+ const displayItem = { ...item , path : displayPath || "." }
399+
341400const { filename, part } = createFilePart (
342- item ,
343- path . join ( result . data . location . directory , item . path ) ,
401+ displayItem ,
402+ absolutePath ,
344403lineRange ,
345404)
346405return {
347406display : Locale . truncateMiddle ( filename , width ) ,
348407value : filename ,
349408isDirectory : item . type === "directory" ,
350- path : item . path ,
409+ path : displayPath || "." ,
351410onSelect : ( ) => {
352411insertPart ( filename , part )
353412} ,
0 commit comments