def driver(): # Open an editor and go to a line where there's a code action b = GPS.EditorBuffer.get(GPS.File("hello.adb")) v = b.current_view() v.goto(b.at(5, 9)) # Wait until the language server has responded to the codeAction request yield wait_language_server("textDocument/codeAction") # Verify that one codeAction message has been created m = GPS.Message.list() gps_assert(len(m), 1, "there should be one message at this point") gps_assert(m[0].get_category(), "_internal_code_actions", "we have a message, but not in the expected category") b.click_on_side_column(5, 1, "gps-light-bulb") # Wait for the language server yield wait_language_server("workspace/executeCommand") # Check that the edits have been received gps_assert(b.get_chars(b.at(5, 1), b.at(6, 1)).strip(), 'Put_Line (Item => "hello");', "edits not received") yield wait_language_server("textDocument/codeAction") m = GPS.Message.list(category="_internal_code_actions") gps_assert(len(m), 0, "there should be no code action message")
def run_test(): buf = GPS.EditorBuffer.get(GPS.File('main.adb')) buf.current_view().goto(buf.at(5, 10)) # wait LSP responses has been processed to have folding information if GPS.LanguageServer.is_enabled_for_language_name("Ada"): yield wait_tasks(other_than=known_tasks) GPS.execute_action('goto declaration') yield wait_language_server('textDocument/declaration') current_buf = GPS.EditorBuffer.get() gps_assert(current_buf.file(), GPS.File('hello_world.ads'), "'goto declaration' did not open the right file") current_loc = current_buf.main_cursor().location() gps_assert(current_loc, current_buf.at(3, 33), "'goto declaration' did not jump to right location") # wait LSP responses has been processed to have folding information if GPS.LanguageServer.is_enabled_for_language_name("Ada"): yield wait_tasks(other_than=known_tasks) GPS.execute_action('goto body') yield wait_language_server('textDocument/implementation') current_buf = GPS.EditorBuffer.get() gps_assert(current_buf.file(), GPS.File('hello_world.adb'), "'goto body' did not open the right file") current_loc = current_buf.main_cursor().location() gps_assert(current_loc, current_buf.at(5, 33), "'goto body' did not jump to right location")
def driver(): buf = GPS.EditorBuffer.get(GPS.File("test_fold.adb")) yield wait_language_server("textDocument/foldingRange") buf.select(buf.at(10, 11), buf.at(15, 11)) GPS.execute_action("Cut to Clipboard") yield wait_language_server("textDocument/foldingRange") buf.at(7, 1).block_fold() buf.current_view().goto(buf.at(7, 19)) GPS.execute_action("Paste from Clipboard") yield wait_language_server("textDocument/foldingRange") # Verify that the contents is what we logically expect gps_assert(buf.get_chars(), expected, "Buffer corruption when inserting after folded block") # Verify that the logical contents correspond to the contents # on screen! g = buf.gtk_text_buffer() gps_assert(buf.get_chars(), g.get_text(g.get_start_iter(), g.get_end_iter(), False), "Corruption between the visible text and the logical text") # Last layer of safety: verify that saving + undo works buf.undo() buf.undo() buf.save(file=GPS.File("out.txt"))
def driver(): # Open an editor and go to a line where there's a code action b = GPS.EditorBuffer.get(GPS.File("main.c")) v = b.current_view() v.goto(b.at(5, 8)) # Wait until the language server has responded to the codeAction request yield wait_language_server("textDocument/codeAction", "C") # Verify that one codeAction message has been created m = GPS.Message.list() gps_assert(len(m), 1, "there should be one message at this point") gps_assert(m[0].get_category(), "_internal_code_actions", "we have a message, but not in the expected category") # Click on the side action b.click_on_side_icon(5, 1, "gps-codefix") # Allow a timeout for the asynchronous popup of the menu yield timeout(1000) menu = get_widget_by_name("gnatstudio_code_actions_menu") gps_assert(menu is not None, True, "no menu found") # Check that the menu contains the "Name parameters" action item = menu.get_children()[0] gps_assert(item.get_label(), "Expand macro 'FOO'", "the menu item doesn' have the right title") # Now activate the menu item and wait for the application of the edits item.activate() yield wait_language_server("workspace/executeCommand", "C") # Check that the edits have been received gps_assert( b.get_chars(b.at(5, 1), b.at(6, 1)).strip(), 'if (0 > 2)', "edits not received") yield wait_language_server("textDocument/codeAction", "C") m = GPS.Message.list(category="_internal_code_actions") gps_assert(len(m), 0, "there should be no code action message")
def driver(): yield wait_tasks() b = GPS.EditorBuffer.get(GPS.File("p.ads")) # Execute a first "find all references" for Foo and check the result b.current_view().goto(b.at(2, 4)) GPS.execute_action("Find All References") yield wait_language_server("textDocument/references") gps_assert(len(GPS.Message.list(category="References for Foo (p.ads:2)")), 2, "There should be two references for Foo") # Simulate a file change on the filesystem for a file that has never # been opened shutil.copy("q.ads.lots", "q.ads") # Wait a bit for the filesystem + the ALS to catch up yield timeout(2000) # Re-execute the request and verify that we have updated results b.current_view().goto(b.at(2, 4)) GPS.execute_action("Find All References") yield wait_language_server("textDocument/references") gps_assert(len(GPS.Message.list(category="References for Foo (p.ads:2)")), 5, "There should now be five references for Foo") # Now do the same as above, after deleting the file os.remove("q.ads") yield timeout(2000) b.current_view().goto(b.at(2, 4)) GPS.execute_action("Find All References") yield wait_language_server("textDocument/references") gps_assert(len(GPS.Message.list(category="References for Foo (p.ads:2)")), 1, "There should now be one references for Foo")
def driver(): def is_valid(expected, msg): """ `expected` : bool indicating if we should have a code action `msg` : string for error message """ m = GPS.Message.list() if expected: gps_assert(len(m), 1, "error at " + msg) gps_assert(m[0].get_category(), "_internal_code_actions", "wrong category") else: gps_assert(len(m), 0, "error at " + msg) # Open an editor and go to a line where there's a code action b = GPS.EditorBuffer.get(GPS.File("foo.adb")) v = b.current_view() # go to the start of Hello and wait for the codeaction v.goto(b.at(2, 28)) yield wait_language_server("textDocument/codeAction") is_valid(True, "start of Hello") # go to the last index inside hello v.goto(b.at(2, 32)) yield wait_language_server("textDocument/codeAction") is_valid(True, "end of Hello") # go to the first index before hello v.goto(b.at(2, 27)) yield wait_language_server("textDocument/codeAction") is_valid(False, "before Hello") # go to the last index inside hello v.goto(b.at(2, 33)) yield wait_language_server("textDocument/codeAction") is_valid(False, "after Hello")
def driver(): GPS.Preference("clangd-BasedOnStyle").set("LLVM") b = GPS.EditorBuffer.get(GPS.File("main.cpp")) yield wait_tasks() # Autoindent file with the LLVM preset GPS.execute_action("autoindent file") yield wait_language_server('textDocument/formatting', 'C++') yield wait_idle() # Verify that the proper indentation is produced txt = b.get_chars(b.beginning_of_buffer(), b.end_of_buffer()) gps_assert(txt, LLVM, "Wrong autoindent") b.undo() # Autoindent file with the Google preset GPS.Preference("clangd-BasedOnStyle").set("Google") GPS.execute_action("autoindent file") yield wait_language_server('textDocument/formatting', 'C++') yield wait_idle() txt = b.get_chars(b.beginning_of_buffer(), b.end_of_buffer()) gps_assert(txt, Google, "Wrong autoindent") b.undo() # Autoindent file with the Chromium preset GPS.Preference("clangd-BasedOnStyle").set("Chromium") GPS.execute_action("autoindent file") yield wait_language_server('textDocument/formatting', 'C++') yield wait_idle() txt = b.get_chars(b.beginning_of_buffer(), b.end_of_buffer()) gps_assert(txt, Chromium, "Wrong autoindent") b.undo() # Autoindent file with the Mozilla preset GPS.Preference("clangd-BasedOnStyle").set("Mozilla") GPS.execute_action("autoindent file") yield wait_language_server('textDocument/formatting', 'C++') yield wait_idle() txt = b.get_chars(b.beginning_of_buffer(), b.end_of_buffer()) gps_assert(txt, Mozilla, "Wrong autoindent") b.undo() # Autoindent file with the WebKit preset GPS.Preference("clangd-BasedOnStyle").set("WebKit") GPS.execute_action("autoindent file") yield wait_language_server('textDocument/formatting', 'C++') yield wait_idle() txt = b.get_chars(b.beginning_of_buffer(), b.end_of_buffer()) gps_assert(txt, WebKit, "Wrong autoindent") b.undo() # Autoindent file with the Microsoft preset GPS.Preference("clangd-BasedOnStyle").set("Microsoft") GPS.execute_action("autoindent file") yield wait_language_server('textDocument/formatting', 'C++') yield wait_idle() txt = b.get_chars(b.beginning_of_buffer(), b.end_of_buffer()) gps_assert(txt, Microsoft, "Wrong autoindent") b.undo() # Autoindent file with the GNU preset GPS.Preference("clangd-BasedOnStyle").set("GNU") GPS.execute_action("autoindent file") yield wait_language_server('textDocument/formatting', 'C++') yield wait_idle() txt = b.get_chars(b.beginning_of_buffer(), b.end_of_buffer()) gps_assert(txt, GNU, "Wrong autoindent") b.undo() GPS.Preference("clangd-BasedOnStyle").set("LLVM") # Autoindent file with the different ContinuationIndentWidth value GPS.Preference("clangd-ContinuationIndentWidth").set(4) GPS.execute_action("autoindent file") yield wait_language_server('textDocument/formatting', 'C++') yield wait_idle() txt = b.get_chars(b.beginning_of_buffer(), b.end_of_buffer()) gps_assert(txt, ContinuationIndentWidth, "Wrong autoindent") GPS.Preference("clangd-ContinuationIndentWidth").set(2) b.undo() #ColumnLimit GPS.Preference("Src-Editor-Highlight-Column").set(40) GPS.execute_action("autoindent file") yield wait_language_server('textDocument/formatting', 'C++') yield wait_idle() txt = b.get_chars(b.beginning_of_buffer(), b.end_of_buffer()) gps_assert(txt, ColumnLimit, "Wrong autoindent") GPS.Preference("Src-Editor-Highlight-Column").set(80) b.undo() #IndentWidth GPS.Preference("C-Indent-Level").set(4) GPS.execute_action("autoindent file") yield wait_language_server('textDocument/formatting', 'C++') yield wait_idle() txt = b.get_chars(b.beginning_of_buffer(), b.end_of_buffer()) gps_assert(txt, IndentWidth, "Wrong autoindent") GPS.Preference("C-Indent-Level").set(2) b.undo() #UseTab will be tested in TC14-011 #ReflowComments GPS.Preference("C-Indent-Comments").set(False) GPS.Preference("Src-Editor-Highlight-Column").set(40) GPS.execute_action("autoindent file") yield wait_language_server('textDocument/formatting', 'C++') yield wait_idle() txt = b.get_chars(b.beginning_of_buffer(), b.end_of_buffer()) gps_assert(txt, ReflowComments, "Wrong autoindent") GPS.Preference("C-Indent-Comments").set(True) GPS.Preference("Src-Editor-Highlight-Column").set(80) b.undo()