diff --git a/flycheck-fsharp.el b/flycheck-fsharp.el index de069d5..3e111f6 100644 --- a/flycheck-fsharp.el +++ b/flycheck-fsharp.el @@ -37,6 +37,34 @@ (defun flycheck-fsharp--can-make-request-p () (fsharp-ac-can-make-request t)) +(defun flycheck-verify-fsautocomlete (_checker) + "Verify the F# syntax checker." + (let* ((host (fsharp-ac--hostname (buffer-file-name))) + (process (fsharp-ac-completion-process host)) + (status (when process (process-status process))) + (project-file (when (eq status 'run) (fsharp-ac--in-project-p (buffer-file-name)))) + (projects (when (eq status 'run) (hash-table-keys fsharp-ac--project-data))) + (command (when process (combine-and-quote-strings (process-command process))))) + (cons + (flycheck-verification-result-new + :label "FSharp.AutoComplete process" + :message (cond + ((eq status 'run) command) + (status (format "Invalid process status: %s (%s)" command status)) + ("not running")) + :face (if (eq status 'run) 'success '(bold error))) + (when (eq status 'run) + (list (flycheck-verification-result-new + :label "F# Project" + :message (or project-file "None") + :face (if project-file 'success '(bold warning))) + (flycheck-verification-result-new + :label "Loaded Projects" + :message (if projects + (mapconcat #'identity projects ", ") + "No projects loaded") + :face (if projects 'success '(bold warning)))))))) + (defun flycheck-fsharp-fsautocomplete-lint-start (checker callback) "Start a F# syntax check with CHECKER. CALLBACK is the status callback passed by Flycheck." @@ -52,6 +80,7 @@ CALLBACK is the status callback passed by Flycheck." See URL `https://github.com/fsharp/FsAutoComplete'." :start #'flycheck-fsharp-fsautocomplete-lint-start :predicate #'flycheck-fsharp--can-make-request-p + :verify #'flycheck-verify-fsautocomlete :modes '(fsharp-mode)) (defvar flycheck-fsharp--error-callback-info nil) @@ -68,6 +97,7 @@ See URL `https://github.com/fsharp/FsAutoComplete'." :start #'flycheck-fsharp-fsautocomplete-start :modes '(fsharp-mode) :predicate #'flycheck-fsharp--can-make-request-p + :verify #'flycheck-verify-fsautocomlete :next-checkers '((info . fsharp-fsautocomplete-lint))) (defun flycheck-fsharp-handle-lint (data) diff --git a/fsharp-mode-completion.el b/fsharp-mode-completion.el index 5cd0efb..e8c24b2 100644 --- a/fsharp-mode-completion.el +++ b/fsharp-mode-completion.el @@ -84,7 +84,8 @@ If set to nil, display in a help buffer instead.") (push (cons host process) fsharp-ac-completion-process-alist)) (defun fsharp-ac-completion-process-del (host) - (delq (assoc host fsharp-ac-completion-process-alist) fsharp-ac-completion-process-alist)) + (setq fsharp-ac-completion-process-alist + (delq (assoc host fsharp-ac-completion-process-alist) fsharp-ac-completion-process-alist))) (defvar fsharp-ac--project-data (make-hash-table :test 'equal) "Data returned by fsautocomplete for loaded projects.") @@ -246,9 +247,8 @@ For indirect buffers return the truename of the base buffer." (defun fsharp-ac/load-file (file) "Start the compiler binding for an individual F# script FILE." - (when (and (fsharp-ac--script-file-p file) (file-exists-p file)) - (unless (fsharp-ac--process-live-p (fsharp-ac--hostname file)) - (fsharp-ac/start-process)) + (when (and (fsharp-ac--script-file-p file) (not (fsharp-ac--process-live-p (fsharp-ac--hostname file)))) + (fsharp-ac/start-process) (add-hook 'after-save-hook 'fsharp-ac--load-after-save nil 'local))) (defun fsharp-ac--load-after-save () @@ -270,6 +270,9 @@ For indirect buffers return the truename of the base buffer." (downcase (file-name-extension file))))) (defun fsharp-ac--in-project-p (file) + "Return F# project file for source FILE. + +Return nil if FILE is not part of a F# project." (gethash file fsharp-ac--project-files)) (defun fsharp-ac--reset ()