[gnome-builder] Revert "GVls: Disabling Ide.Indenter implementation"



commit 5cafa9ee71edda2b93e3b93fbe0745ccb92e632f
Author: Christian Hergert <chergert redhat com>
Date:   Sat Dec 14 12:41:37 2019 -0800

    Revert "GVls: Disabling Ide.Indenter implementation"
    
    This reverts commit d26fd1193e55813aa81459f50c13176b67952ab9.

 src/plugins/gvls/gvls.plugin    |   1 +
 src/plugins/gvls/gvls_plugin.py | 160 ++++++++++++++++++++--------------------
 2 files changed, 81 insertions(+), 80 deletions(-)
---
diff --git a/src/plugins/gvls/gvls.plugin b/src/plugins/gvls/gvls.plugin
index 8695ed0da..a1d48c8a1 100644
--- a/src/plugins/gvls/gvls.plugin
+++ b/src/plugins/gvls/gvls.plugin
@@ -13,3 +13,4 @@ X-Completion-Provider-Languages-Priority=0
 X-Highlighter-Languages=vala
 X-Symbol-Resolver-Languages=vala
 X-Diagnostic-Provider-Languages=vala
+X-Indenter-Languages=vala
diff --git a/src/plugins/gvls/gvls_plugin.py b/src/plugins/gvls/gvls_plugin.py
index cb362dadc..3346eab68 100644
--- a/src/plugins/gvls/gvls_plugin.py
+++ b/src/plugins/gvls/gvls_plugin.py
@@ -233,90 +233,90 @@ class GVlsDiagnosticProvider(Ide.LspDiagnosticProvider):
 # Copyright 2015 Christian Hergert <christian hergert me>
 # Copyright 2019 Daniel Espinosa <esodan gnome org>
 #
-# class GVlsIdenter (Ide.Object, Ide.Indenter):
-#     def is_trigger (self, evkey):
-#         val = evkey.keyval
-#         if val == Gdk.KEY_Return or val == Gdk.KEY_KP_Enter:
-#             return True
-#         if val == Gdk.KDEY_slash:
-#             return True
-#         return False
-#     def format (self, text_view, begin, end, evkey):
-#         source_view = text_view
-#         was_newline = self.is_newline_keyval (evkey.keyval)
-#         copy = end
-#         cursor_offset = 0
+class GVlsIdenter (Ide.Object, Ide.Indenter):
+    def is_trigger (self, evkey):
+        val = evkey.keyval
+        if val == Gdk.KEY_Return or val == Gdk.KEY_KP_Enter:
+            return True
+        if val == Gdk.KDEY_slash:
+            return True
+        return False
+    def format (self, text_view, begin, end, evkey):
+        source_view = text_view
+        was_newline = self.is_newline_keyval (evkey.keyval)
+        copy = end
+        cursor_offset = 0
         # Move us back to the just inserted character
-#         copy.backward_char ()
+        copy.backward_char ()
         # If we are in a comment, continue the indentation
-#         if (self.in_comment (text_view, copy)):
+        if (self.in_comment (text_view, copy)):
             # maybe close a multiline comment
-#             if (copy.get_char () == '/'):
-#                 close = copy
-#             if (close.backward_char () and close.get_char () == ' ' and close.backward_char () and 
close.get_char () == '*'):
-#                 begin.backward_char ()
-#                 begin.backward_char ()
-#                 return ("/", cursor_offset)
-#         if (was_newline):
-#             return indent_comment (text_view, copy)
-#         if (self.is_newline_in_braces (copy)):
-#             prefix = self.copy_indent (text_view, copy)
-#             if (source_view.insert_spaces_instead_of_tabs):
-#                 indent = "    "
-#             else:
-#                 indent = "\t"
-#             cursor_offset = -prefix.length - 1
-#             return (prefix + indent + "\n" + prefix, cursor_offset)
-#         if (was_newline):
-#             return (self.copy_indent (text_view, copy), cursor_offset)
-#         return null
-#     def copy_indent (self, text_view, iter):
-#         begin = iter
-#         begin.set_line_offset (0)
-#         end = begin
-#         while (not end.ends_line () and end.get_char ().isspace () and end.forward_char ()):
+            if (copy.get_char () == '/'):
+                close = copy
+            if (close.backward_char () and close.get_char () == ' ' and close.backward_char () and 
close.get_char () == '*'):
+                begin.backward_char ()
+                begin.backward_char ()
+                return ("/", cursor_offset)
+        if (was_newline):
+            return indent_comment (text_view, copy)
+        if (self.is_newline_in_braces (copy)):
+            prefix = self.copy_indent (text_view, copy)
+            if (source_view.insert_spaces_instead_of_tabs):
+                indent = "    "
+            else:
+                indent = "\t"
+            cursor_offset = -prefix.length - 1
+            return (prefix + indent + "\n" + prefix, cursor_offset)
+        if (was_newline):
+            return (self.copy_indent (text_view, copy), cursor_offset)
+        return null
+    def copy_indent (self, text_view, iter):
+        begin = iter
+        begin.set_line_offset (0)
+        end = begin
+        while (not end.ends_line () and end.get_char ().isspace () and end.forward_char ()):
             # Do nothing
-#             pass
-#         return begin.get_slice (end)
-#     def get_line_text (self, iter):
-#         begin = iter
-#         end = iter
-#         begin.set_line_offset (0)
-#         if (not end.ends_line ()):
-#             end.forward_to_line_end ()
-#         return begin.get_slice (end)
-#     def indent_comment (self, text_view, iter):
-#         line = self.get_line_text (iter).strip ();
+            pass
+        return begin.get_slice (end)
+    def get_line_text (self, iter):
+        begin = iter
+        end = iter
+        begin.set_line_offset (0)
+        if (not end.ends_line ()):
+            end.forward_to_line_end ()
+        return begin.get_slice (end)
+    def indent_comment (self, text_view, iter):
+        line = self.get_line_text (iter).strip ();
         # continue with another single line comment
-#         if line.has_prefix ("//"):
-#             return copy_indent (text_view, iter) + "// "
+        if line.has_prefix ("//"):
+            return copy_indent (text_view, iter) + "// "
         # comment is closed, copy indent, possibly trimming extra space
-#         if (line.has_suffix ("*/")):
-#             if (line.has_prefix ("*")):
-#                 s = GLib.String ()
-#                 s.append (self.copy_indent (text_view, iter))
-#                 if (s.str.endswith (" ")):
-#                     s.truncate (len (s) - 1)
-#                 return s.str
-#         if (line.endswith ("/*") and not line.endswith ("*/")):
-#             return self.copy_indent (text_view, iter) + " * "
-#         elif (line.has_prefix ("*")):
-#             return self.copy_indent (text_view, iter) + "* "
-#         return self.copy_indent (text_view, iter)
-#     def in_comment (self, text_view, iter):
-#         buffer = text_view.get_buffer ()
-#         copy = iter
-#         copy.backward_char ()
-#         return buffer.iter_has_context_class (copy, "comment")
-#     def is_newline_keyval (self, keyval):
-#         if keyval == Gdk.KEY_Return or keyval == Gdk.KEY_KP_Enter:
-#             return True
-#         return False
-#     def is_newline_in_braces (self, iter):
-#         prev = iter
-#         next = iter
-#         prev.backward_char ()
-#         next.forward_char ()
-#         ret = (prev.get_char () == '{') and (iter.get_char () == '\n')
-#         return ret and (next.get_char () == '}')
+        if (line.has_suffix ("*/")):
+            if (line.has_prefix ("*")):
+                s = GLib.String ()
+                s.append (self.copy_indent (text_view, iter))
+                if (s.str.endswith (" ")):
+                    s.truncate (len (s) - 1)
+                return s.str
+        if (line.endswith ("/*") and not line.endswith ("*/")):
+            return self.copy_indent (text_view, iter) + " * "
+        elif (line.has_prefix ("*")):
+            return self.copy_indent (text_view, iter) + "* "
+        return self.copy_indent (text_view, iter)
+    def in_comment (self, text_view, iter):
+        buffer = text_view.get_buffer ()
+        copy = iter
+        copy.backward_char ()
+        return buffer.iter_has_context_class (copy, "comment")
+    def is_newline_keyval (self, keyval):
+        if keyval == Gdk.KEY_Return or keyval == Gdk.KEY_KP_Enter:
+            return True
+        return False
+    def is_newline_in_braces (self, iter):
+        prev = iter
+        next = iter
+        prev.backward_char ()
+        next.forward_char ()
+        ret = (prev.get_char () == '{') and (iter.get_char () == '\n')
+        return ret and (next.get_char () == '}')
 


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