Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions flycheck-fsharp.el
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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)
Expand All @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions fsharp-mode-completion.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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 ()
Expand All @@ -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 ()
Expand Down