Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command-line option to let #fileIDs be full paths #66777

Open
dabrahams opened this issue Jun 20, 2023 · 3 comments
Open

Command-line option to let #fileIDs be full paths #66777

dabrahams opened this issue Jun 20, 2023 · 3 comments
Labels
feature A feature request or implementation triage needed This issue needs more specific labels

Comments

@dabrahams
Copy link
Contributor

dabrahams commented Jun 20, 2023

I understand the reasons for #fileID as it is, but if I want to jump to the location of an assertion, seeing the result of #fileID in a diagnostic is pretty unhelpful in a large project. I'll append the emacs-lisp code it takes for me to (hackily) get to the line (in most cases). I hope you'll agree this is pretty horrible. Users of IDEs other than Xcode will have to do similar things. I don't care at all about the size of my binaries during development, and ideally I'd like debug builds to include the full #filePath in assertions, but it might be better to just have a command-line option for this.

(defun dwa/path-tails-matching (path paths)
  "Returns the elements of PATHS with PATH as their suffix, matching by path component."
  (let ((tail (file-name-concat "/" path)))
    (seq-filter (lambda (full-path) (string-suffix-p tail full-path)) paths)))

(defun dwa/compilation-parse-errors-filename-in-project (path-in-error)
  "If PATH-IN-ERROR is found in the filesystem, returns it
unchanged; otherwise tries to return a unique file in the current
project likely to be identified by PATH-IN-ERROR.  Returns
PATH-IN-ERROR unchanged if no such file can be found."
  (if (file-exists-p path-in-error) path-in-error
    ;; First look for relative path suffixes.
    (let* ((candidates (project-files (project-current t)))
	   (full-matches (dwa/path-tails-matching path-in-error candidates)))

      ;; If not found, try just the filename component of
      ;; path-in-error; Swift assertions are weird and include a
      ;; module name that doesn't necessarily correspond to anything in the
      ;; filesystem.
      (cond ((null full-matches)
	     (let ((filename-matches
		   (dwa/path-tails-matching (file-name-nondirectory path-in-error) candidates)))
	       (cond ((null filename-matches) path-in-error)
		     ;; unique match; return it
		     ((null (cadr filename-matches)) (car filename-matches))
		     ;; multiple matches; consider prompting for the user to select one.
		     (t path-in-error))))
	    ;; unique match; return it
	    ((null (cadr matches)) (car matches))
	     ; multiple matches; consider prompting for the user to select one.
	    (t path-in-error)))))

(setq compilation-parse-errors-filename-function 'dwa/compilation-parse-errors-filename-in-project)
@dabrahams dabrahams added feature A feature request or implementation triage needed This issue needs more specific labels labels Jun 20, 2023
@grynspan
Copy link
Contributor

Since #fileID needs a specific machine-parseable format, perhaps a better solution would be to have the offending functions use #file instead (once that defaults to equalling #fileID.) Then, you can toggle #file back to equalling #filePath in your local configuration.

@dabrahams
Copy link
Contributor Author

I'm open to any solution that allows me to see the full path to the file in debug build diagnostics

@dabrahams
Copy link
Contributor Author

Here is a horrible workaround I came up with: use an SPM plugin to generate a file containing an internal version of all the standard library functions that use #fileID, in each target.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A feature request or implementation triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

2 participants