emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/dart-mode 6397b3d 115/192: Clean up the way the SDK is con


From: ELPA Syncer
Subject: [nongnu] elpa/dart-mode 6397b3d 115/192: Clean up the way the SDK is configured
Date: Sun, 29 Aug 2021 11:02:01 -0400 (EDT)

branch: elpa/dart-mode
commit 6397b3dfd6eeafc6de22c11a0b66ba8e6b276bc1
Author: Natalie Weizenbaum <nex342@gmail.com>
Commit: Natalie Weizenbaum <nex342@gmail.com>

    Clean up the way the SDK is configured
---
 CHANGELOG.md | 14 ++++++++++--
 README.md    | 12 ++++++++++
 dart-mode.el | 73 +++++++++++++++++++++++++++++++++++-------------------------
 3 files changed, 67 insertions(+), 32 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 302b2c3..845c80d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,7 @@
 ## 1.0.0
 
+### Additions
+
 * Added a `dart-show-hover` command bound to `C-c ?` which displays information
   about the Dart API under the cursor.
 
@@ -23,5 +25,13 @@
   `dart-expand-parameters` command bound to `M-?` which inserts the parameter
   list for the chosen completion.
 
-* `dart-executable-path`'s default value is now set correctly even if the
-  executable named `dart` on the user's path is a symlink or a wrapper script.
+* Added a `dart-sdk-path` variable.
+
+### Replacements
+
+* `dart-executable-path` is now a function rather than a variable, so that it
+  updates when `dart-sdk-path` is updated.
+
+### Removals
+
+* The `dart-analysis-server-snapshot-path` variable has been removed.
diff --git a/README.md b/README.md
index fbbc4b5..2b4472f 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,7 @@
 `dart-mode` is a major mode for editing Dart files in Emacs.
 
 * [Installation](#installation)
+  * [General Configuration](#general-configuration)
 * [Dart Analyzer](#dart-analyzer)
   * [Error Checking](#error-checking)
   * [Seeing Information](#seeing-information)
@@ -19,6 +20,17 @@
     M-x package-install [RET] dart-mode
     ```
 
+### General Configuration
+
+The `dart-sdk-path` variable can be set to tell Emacs where to find the Dart
+SDK. This is used to run the [Dart analysis server](#dart-analyzer) and the 
Dart
+formatter. By default, it's set by finding the `dart` executable on the system
+path.
+
+Note that user code that wants to run Dart scripts can use the
+`dart-executable-path` function to locate the `dart` executable itself in the
+SDK's `bin/` directory.
+
 ## Dart Analyzer
 
 `dart-mode` supports the Dart analysis server, which runs in the background and
diff --git a/dart-mode.el b/dart-mode.el
index 1a1814d..1dde417 100644
--- a/dart-mode.el
+++ b/dart-mode.el
@@ -253,6 +253,41 @@ Any stderr is logged using dart-log. Returns nil if the 
exit code is non-0."
     (if (eq (nth 2 result) 0) (nth 0 result))))
 
 
+;;; General configuration
+
+(defcustom dart-sdk-path
+  ;; Use Platform.resolvedExecutable so that this logic works through symlinks
+  ;; and wrapper scripts.
+  (-when-let (dart (executable-find "dart"))
+    (dart--with-temp-file input
+      (with-temp-file input (insert "
+        import 'dart:io';
+
+        void main() {
+          print(Platform.resolvedExecutable);
+        }
+        "))
+      (-when-let (result (dart--try-process dart input))
+        (file-name-directory
+         (directory-file-name
+          (file-name-directory (string-trim result)))))))
+  "The absolute path to the root of the Dart SDK."
+  :group 'dart-mode
+  :type 'directory
+  :package-version '(dart-mode . "1.0.0"))
+
+(defun dart-executable-path ()
+  "The absolute path to the 'dart' executable.
+
+Returns nil if `dart-sdk-path' is nil."
+  (when dart-sdk-path
+    (concat dart-sdk-path
+            (file-name-as-directory "bin")
+            (if (memq system-type '(ms-dos windows-nt))
+                "dart.exe"
+              "dart"))))
+
+
 ;;; CC configuration
 
 (c-lang-defconst c-symbol-start
@@ -703,34 +738,13 @@ navigation, and more."
 (defvar dart--analysis-server nil
   "The instance of the Dart analysis server we are communicating with.")
 
-(defcustom dart-executable-path
-  ;; Use Platform.resolvedExecutable so that this logic works through symlinks
-  ;; and wrapper scripts.
-  (-when-let (dart (executable-find "dart"))
-    (dart--with-temp-file input
-      (with-temp-file input (insert "
-        import 'dart:io';
-
-        void main() {
-          print(Platform.resolvedExecutable);
-        }
-        "))
-      (-when-let (result (dart--try-process dart input))
-        (string-trim result))))
-  "The absolute path to the 'dart' executable."
-  :group 'dart-mode
-  :type 'file
-  :package-version '(dart-mode . "1.0.0"))
-
-(defcustom dart-analysis-server-snapshot-path
-  (when dart-executable-path
-    (concat (file-name-directory dart-executable-path)
+(defun dart--analysis-server-snapshot-path ()
+  (when dart-sdk-path
+    (concat dart-sdk-path
+            (file-name-as-directory "bin")
             (file-name-as-directory "snapshots")
             "analysis_server.dart.snapshot"))
-  "The absolute path to the snapshot file that runs the Dart analysis server."
-  :group 'dart-mode
-  :type 'file
-  :package-version '(dart-mode . "0.12"))
+  "The absolute path to the snapshot file that runs the Dart analysis server.")
 
 (defvar dart-analysis-roots nil
   "The list of analysis roots that are known to the analysis server.
@@ -796,8 +810,8 @@ directory or the current file directory to the analysis 
roots."
          (dart-process
           (start-process "dart-analysis-server"
                          "*dart-analysis-server*"
-                         dart-executable-path
-                         dart-analysis-server-snapshot-path
+                         (dart-executable-path)
+                         (dart--analysis-server-snapshot-path)
                          "--no-error-notification")))
     (set-process-query-on-exit-flag dart-process nil)
     (setq dart--analysis-server
@@ -1808,8 +1822,7 @@ Key bindings:
   (c-common-init 'dart-mode)
   (c-set-style "dart")
   (when dart-enable-analysis-server
-    (if (or (null dart-executable-path)
-            (null dart-analysis-server-snapshot-path))
+    (if (null dart-sdk-path)
         (dart-log
          "Cannot find `dart' executable or Dart analysis server snapshot.")
       (dart--start-analysis-server-for-current-buffer)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]