[gnome-builder: 77/139] eslint: port to libide-code and libide-foundry



commit d285486b65d196a5c48d20bcb152adff247e2606
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 9 17:17:06 2019 -0800

    eslint: port to libide-code and libide-foundry

 src/plugins/eslint/eslint.plugin    | 12 ++++---
 src/plugins/eslint/eslint_plugin.py | 66 +++++++++++++++++++++----------------
 src/plugins/eslint/meson.build      |  4 +--
 3 files changed, 47 insertions(+), 35 deletions(-)
---
diff --git a/src/plugins/eslint/eslint.plugin b/src/plugins/eslint/eslint.plugin
index 13730315c..80e13c99b 100644
--- a/src/plugins/eslint/eslint.plugin
+++ b/src/plugins/eslint/eslint.plugin
@@ -1,9 +1,11 @@
 [Plugin]
-Module=eslint_plugin
-Name=eslint
-Loader=python3
-Description=Provides javascript lints
 Authors=Georg Vienna <georg vienna himbarsoft com>
 Copyright=Copyright © 2017 Georg Vienna <georg vienna himbarsoft com>
-X-Diagnostic-Provider-Languages=js
+Description=Provides javascript lints
+Loader=python3
+Hidden=true
+Module=eslint_plugin
+Name=eslint
 X-Diagnostic-Provider-Languages-Priority=100
+X-Diagnostic-Provider-Languages=js
+X-Builder-ABI=@PACKAGE_ABI@
diff --git a/src/plugins/eslint/eslint_plugin.py b/src/plugins/eslint/eslint_plugin.py
index 91e6075b6..847c35f1e 100644
--- a/src/plugins/eslint/eslint_plugin.py
+++ b/src/plugins/eslint/eslint_plugin.py
@@ -24,15 +24,11 @@ import gi
 import json
 import threading
 
-gi.require_version('Ide', '1.0')
-
-from gi.repository import (
-    GLib,
-    GObject,
-    Gio,
-    Gtk,
-    Ide,
-)
+from gi.repository import GLib
+from gi.repository import GObject
+from gi.repository import Gio
+from gi.repository import Gtk
+from gi.repository import Ide
 
 _ = Ide.gettext
 
@@ -52,24 +48,34 @@ class ESLintDiagnosticProvider(Ide.Object, Ide.DiagnosticProvider):
         else:
             return 'eslint'  # Just rely on PATH
 
-    def do_diagnose_async(self, file, buffer, cancellable, callback, user_data):
-        self.diagnostics_list = []
-        task = Gio.Task.new(self, cancellable, callback)
-        task.diagnostics_list = []
-
+    def create_launcher(self):
         context = self.get_context()
-        unsaved_file = context.get_unsaved_files().get_unsaved_file(file.get_file())
-        pipeline = self.get_context().get_build_manager().get_pipeline()
-        srcdir = pipeline.get_srcdir()
-        runtime = pipeline.get_configuration().get_runtime()
-        launcher = runtime.create_launcher()
+        srcdir = context.ref_workdir().get_path()
+        launcher = None
+
+        if context.has_project():
+            build_manager = Ide.BuildManager.from_context(context)
+            pipeline = build_manager.get_pipeline()
+            if pipeline is not None:
+                srcdir = pipeline.get_srcdir()
+            runtime = pipeline.get_configuration().get_runtime()
+            launcher = runtime.create_launcher()
+
+        if launcher is None:
+            launcher = Ide.SubprocessLauncher.new(0)
+
         launcher.set_flags(Gio.SubprocessFlags.STDIN_PIPE | Gio.SubprocessFlags.STDOUT_PIPE)
         launcher.set_cwd(srcdir)
 
-        if unsaved_file:
-            file_content = unsaved_file.get_content().get_data().decode('utf-8')
-        else:
-            file_content = None
+        return launcher
+
+    def do_diagnose_async(self, file, file_content, lang_id, cancellable, callback, user_data):
+        self.diagnostics_list = []
+        task = Gio.Task.new(self, cancellable, callback)
+        task.diagnostics_list = []
+
+        launcher = self.create_launcher()
+        srcdir = launcher.get_cwd()
 
         threading.Thread(target=self.execute, args=(task, launcher, srcdir, file, file_content),
                          name='eslint-thread').start()
@@ -87,7 +93,8 @@ class ESLintDiagnosticProvider(Ide.Object, Ide.DiagnosticProvider):
                 launcher.push_argv(file.get_path())
 
             sub_process = launcher.spawn()
-            success, stdout, stderr = sub_process.communicate_utf8(file_content, None)
+            stdin = file_content.get_data().decode('UTF-8')
+            success, stdout, stderr = sub_process.communicate_utf8(stdin, None)
 
             if not success:
                 task.return_boolean(False)
@@ -100,17 +107,17 @@ class ESLintDiagnosticProvider(Ide.Object, Ide.DiagnosticProvider):
                         continue
                     start_line = max(message['line'] - 1, 0)
                     start_col = max(message['column'] - 1, 0)
-                    start = Ide.SourceLocation.new(file, start_line, start_col, 0)
+                    start = Ide.Location.new(file, start_line, start_col)
                     end = None
                     if 'endLine' in message:
                         end_line = max(message['endLine'] - 1, 0)
                         end_col = max(message['endColumn'] - 1, 0)
-                        end = Ide.SourceLocation.new(file, end_line, end_col, 0)
+                        end = Ide.Location.new(file, end_line, end_col)
 
                     severity = SEVERITY_MAP[message['severity']]
                     diagnostic = Ide.Diagnostic.new(severity, message['message'], start)
                     if end is not None:
-                        range_ = Ide.SourceRange.new(start, end)
+                        range_ = Ide.Range.new(start, end)
                         diagnostic.add_range(range_)
                         # if 'fix' in message:
                         # Fixes often come without end* information so we
@@ -129,7 +136,10 @@ class ESLintDiagnosticProvider(Ide.Object, Ide.DiagnosticProvider):
 
     def do_diagnose_finish(self, result):
         if result.propagate_boolean():
-            return Ide.Diagnostics.new(result.diagnostics_list)
+            diagnostics = Ide.Diagnostics()
+            for diag in result.diagnostics_list:
+                diagnostics.add(diag)
+            return diagnostics
 
 
 class ESLintPreferencesAddin(GObject.Object, Ide.PreferencesAddin):
diff --git a/src/plugins/eslint/meson.build b/src/plugins/eslint/meson.build
index d13bcb9c5..754eb171c 100644
--- a/src/plugins/eslint/meson.build
+++ b/src/plugins/eslint/meson.build
@@ -1,4 +1,4 @@
-if get_option('with_eslint')
+if get_option('plugin_eslint')
 
 install_data('eslint_plugin.py', install_dir: plugindir)
 
@@ -8,7 +8,7 @@ install_data('org.gnome.builder.plugins.eslint.gschema.xml',
 configure_file(
           input: 'eslint.plugin',
          output: 'eslint.plugin',
-           copy: true,
+  configuration: config_h,
         install: true,
     install_dir: plugindir,
 )


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