Skip to content

Commit

Permalink
feat: autocomplete works with tilde and absolute dirs (#1216)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-timothy-albert authored Jan 23, 2025
1 parent 94d3b13 commit ee25967
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
11 changes: 7 additions & 4 deletions internal/charm/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ func SchemaFilesInCurrentDir(relativeDir string, fileExtensions []string) []stri
return validFiles
}

targetDir := filepath.Join(workingDir, relativeDir)
targetDir := relativeDir
if !filepath.IsAbs(targetDir) {
targetDir = filepath.Join(workingDir, targetDir)
}

files, err := os.ReadDir(targetDir)
if err != nil {
Expand Down Expand Up @@ -115,9 +118,9 @@ func DirsInCurrentDir(relativeDir string) []string {
return validDirs
}

targetDir := filepath.Join(workingDir, relativeDir)
if filepath.IsAbs(relativeDir) {
targetDir = relativeDir
targetDir := relativeDir
if !filepath.IsAbs(targetDir) {
targetDir = filepath.Join(workingDir, targetDir)
}

files, err := os.ReadDir(targetDir)
Expand Down
15 changes: 10 additions & 5 deletions prompts/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,12 @@ func formatDocument(fileLocation, authHeader string, validate bool) (*workflow.D
}

const (
ErrMsgInvalidFilePath = "please provide a valid file path"
ErrMsgNonExistentFile = "file does not exist"
ErrMessageFileIsDir = "path is a directory, not a file"
ErrMessageFileExt = "file extension '%s' is invalid. Valid extensions are %s"
ErrMsgInvalidURL = "please provide a valid URL"
ErrMsgInvalidFilePath = "please provide a valid file path"
ErrMsgNonExistentFile = "file does not exist"
ErrMsgTildeNotPermitted = "~ paths are not permitted. Please provide the exact path to your file"
ErrMessageFileIsDir = "path is a directory, not a file"
ErrMessageFileExt = "file extension '%s' is invalid. Valid extensions are %s"
ErrMsgInvalidURL = "please provide a valid URL"
)

func validateDocumentLocation(input string, permittedFileExtensions []string) error {
Expand Down Expand Up @@ -544,6 +545,10 @@ func validateURL(parsedURL *url.URL) error {
}

func validateFilePath(input string, permittedFileExtensions []string) error {
if strings.HasPrefix(input, "~/") {
return errors.New(ErrMsgTildeNotPermitted)
}

absPath, err := filepath.Abs(input)
if err != nil {
return errors.New(ErrMsgInvalidFilePath)
Expand Down

0 comments on commit ee25967

Please sign in to comment.