From cf0846d3b3ff5d70fb443ce52fa4f5d26bf7a1a7 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Sat, 20 May 2017 08:56:11 -0400 Subject: [PATCH 21/31] FIXME: split out method implementation within lsp-main.c --- gcc/lsp-main.c | 100 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 54 insertions(+), 46 deletions(-) diff --git a/gcc/lsp-main.c b/gcc/lsp-main.c index e971fc1..00c7940 100644 --- a/gcc/lsp-main.c +++ b/gcc/lsp-main.c @@ -82,57 +82,65 @@ class gcc_lsp_server : public lsp::noop_server void do_text_document_definition (const TextDocumentPositionParams &p, - vec &out) OVERRIDE - { - /* TODO. */ - blt_node *blt - = the_blt_root_node->get_descendant_at_location (p.textDocument.uri, - p.position.line, - p.position.character); - if (!blt) - /* No results. */ - return; + vec &out) OVERRIDE; +}; - blt->dump (stderr); - switch (blt->get_kind ()) +/* class gcc_lsp_server : public lsp::noop_server. */ + +/* Implementation of "textDocument/definition": + find the definition of the symbol at a given source location. */ + +void +gcc_lsp_server::do_text_document_definition (const TextDocumentPositionParams &p, + vec &out) +{ + /* TODO. */ + blt_node *blt + = the_blt_root_node->get_descendant_at_location (p.textDocument.uri, + p.position.line, + p.position.character); + if (!blt) + /* No results. */ + return; + + blt->dump (stderr); + + switch (blt->get_kind ()) + { + case BLT_STRUCT_OR_UNION_SPECIFIER: { - case BLT_STRUCT_OR_UNION_SPECIFIER: - { - /* Attempt to locate the RECORD_TYPE for the - struct-or-union-specifier. */ - tree record_type = blt->get_tree (); - if (!record_type) - return; - - if (1) - the_blt_root_node->dump (stderr); - - /* Find a struct-contents with tree == record_type. */ - is_record_definition pred (record_type); - blt_node *blt_struct_contents - = the_blt_root_node->find_descendant_satisfying (pred); - if (!blt_struct_contents) - return; - - if (1) - blt_struct_contents->dump (stderr); - blt_node *blt_struct_defn = blt_struct_contents->get_parent (); - - Location result; - if (Location_from_blt_node (blt_struct_defn, result)) - out.safe_push (result); - } - break; - - default: - /* No results. */ - return; + /* Attempt to locate the RECORD_TYPE for the + struct-or-union-specifier. */ + tree record_type = blt->get_tree (); + if (!record_type) + return; + + if (1) + the_blt_root_node->dump (stderr); + + /* Find a struct-contents with tree == record_type. */ + is_record_definition pred (record_type); + blt_node *blt_struct_contents + = the_blt_root_node->find_descendant_satisfying (pred); + if (!blt_struct_contents) + return; + + if (1) + blt_struct_contents->dump (stderr); + blt_node *blt_struct_defn = blt_struct_contents->get_parent (); + + Location result; + if (Location_from_blt_node (blt_struct_defn, result)) + out.safe_push (result); } + break; - - } -}; + default: + /* No results. */ + return; + } +} /* Serve LSP on PORT. */ -- 1.8.5.3