@@ 1273,15 1273,45 @@ minibuffer, even without explicitly focusing it."
(defun find-git-repo (dir)
(if (string= "/" dir)
nil
- (if (file-exists-p (expand-file-name "../.git/" dir))
+ (if (file-exists-p (expand-file-name "./.git/" dir))
dir
- (find-git-repo (expand-file-name "../" dir)))))
+ (find-git-repo (file-name-parent-directory dir)))))
+
+ (defun get-csproj-in-directory (dir)
+ (car (directory-files dir
+ :mach-regexp ".*\\.csproj"
+ :count 1)))
+
+ ;; Finds .csproj above current buffer directory, and returns path to the csproj
+ (defun find-csproj (dir root)
+ (if (string-match-p (regexp-quote root) dir)
+ (let ((csproj (get-csproj-in-directory dir)))
+ (if csproj
+ csproj
+ (find-csproj (file-name-parent-directory dir) root)))
+ nil))
+
+ (defun find-current-csproj ()
+ (let ((root (find-project-root))
+ (dir (file-name-directory buffer-file-name)))
+ (find-csproj dir root)))
+
+ (defun extract-project-name ()
+ (interactive)
+ (let ((csproj (find-current-csproj)))
+ (file-name-base csproj)))
(defun file-path-to-namespace ()
(interactive)
- (let ((root (find-project-root))
- (base (file-name-nondirectory buffer-file-name)))
- (substring (replace-regexp-in-string "/" "\." (substring buffer-file-name (length root) (* -1 (length base))) t t) 0 -1))))
+ (let ((root (file-name-directory (find-current-csproj)))
+ (base (file-name-nondirectory buffer-file-name))
+ (project-name (extract-project-name)))
+ (concat
+ project-name
+ "."
+ (substring
+ (replace-regexp-in-string "/" "\." (substring buffer-file-name (length root) (* -1 (length base))) t t)
+ 0 -1)))))
;; Sh, Bash