rosshadden / sublime-xpath

Sublime Text plugin for easier cursor navigation of XML and HTML files using XPath 1.0.
44 stars 10 forks source link

Xpath query not working #27

Closed Toubef closed 7 years ago

Toubef commented 7 years ago

Hi,

I been trying to get this up and running with ST3 but I can't get the xpath query window to show up. I have setup the following from your example:

`[ // NOTE: because this file is named Example, and doesn't end in: (Windows) or (OSX) or (Linux), it is ignored by ST3. // NOTE: not including an arg will use the value from your user preferences, if present, otherwise the default settings

// Move cursor to XML Parse Error
{
    "keys": ["ctrl+alt+super+e"],
    "command": "goto_xml_parse_error"
},

// Copy unique XPaths at cursors to the clipboard
// - without positions - aka hierarchy only mode i.e. `/Root/Node` instead of `/Root/Node[3]`
// - but with whitelisted attributes i.e. `/Root/Node[@id="test"]`
// - with the exact path from the document, not taking into account duplicate namespace declarations aka don't use namespace prefixes from query
{
    "keys": ["ctrl+alt+super+c"],
    "command": "copy_xpath",
    "args": {
        "show_hierarchy_only": true,
        "copy_unique_path_only": true,
        "show_namespace_prefixes_from_query": false,
        "show_attributes_in_hierarchy": true,
        "show_all_attributes": false // if false, include only whitelisted attributes
    }
},

// as above, but include indexes ignoring element name casing, and all attributes
{
    "keys": ["ctrl+shift+alt+super+c"],
    "command": "copy_xpath",
    "args": {
        "show_all_attributes": true,
        "show_hierarchy_only": false,
        "case_sensitive": false
    }
},

// Move cursors to relative nodes (or to open tag, closing tag, both open and closing tag, the attributes in the open tag, the entire node, the contents of the node)
{
    "keys": ["ctrl+alt+super+g"],
    "command": "goto_relative",
    "args": {
        "direction": "previous", // options are: 'self', 'next', 'prev'(ious), 'parent'
        "goto_element": "open" // options are 'open' tag, 'close' tag, 'names' (both open and closing tag), 'open_attributes', 'entire', 'content'
    }
},

// Show XPath Query History
{
    "keys": ["ctrl+alt+super+h"],
    "command": "show_xpath_query_history",
    "args": {
        "global_query_history": true // whether or not to show the global history, or the history specific to the current view
    }
},

// Directly run an XPath query and select the results
{
    "keys": ["ctrl+alt+super+q"],
    "command": "select_results_from_xpath_query",
    "args": {
        "xpath": "//*", // the specific XPath query to execute
        "goto_element": "names", // same options available as for goto_relative
        "goto_attribute": "value" // options are name, value, entire
    }
},

// Re-run the most recently used XPath query and select the results
{
    "keys": ["ctrl+alt+super+r"],
    "command": "rerun_last_xpath_query_and_select_results",
    "args": {
        "global_query_history": true, // whether or not to use the last query from the global history, or the history specific to the current view
        "goto_element": "names", // same options available as for goto_relative
        "goto_attribute": "value" // options are name, value, entire
    }
},

// Clean (HTML) "tag soup"
{
    "keys": ["ctrl+alt+super+s"],
    "command": "clean_tag_soup"
},

// Show the XPath query input box
{
    "keys": ["ctrl+shift+alt+q"],
    "command": "query_xpath",
    "args": {
        "prefill_query": "//text()", // an XPath query to put into the input box by default - can omit and use "prefill_path_at_cursor": true instead to use the path of the node under the first cursor
        "live_mode": true, // as per settings
        "normalize_whitespace_in_preview": false, // as per settings
        "intelligent_auto_complete": true, // as per settings
        "goto_element": "names", // same options available as for goto_relative
        "goto_attribute": "value", // options are name, value, entire
        "max_results_to_show": 1000 // as per settings
    }
},

]`

What am I doing wrong?

Br, Toube

keith-hall commented 7 years ago

Hi Toube,

Sorry to hear that you are having trouble.

You shouldn't need to define any keybindings to be able to use this plugin. It should just be a case of opening the Command Palette (Tools menu) and selecting a choice beginning with XPath: like Query Document. These entries only show up if the XML syntax highlighting is active for the current file.

If they still aren't appearing, please could you open the ST console (View menu) and check for errors. Maybe paste the whole log here, as the more information we have, the easier it is to debug :)

Thanks

Toubef commented 7 years ago

Hi Keith,

thanks for pointing this out, It works :) Any idea why I can't get the keyboard shortcut to work, ctrl+shift+alt+q? { "keys": ["ctrl+shift+alt+q"], "command": "query_xpath", "args": { "prefill_query": "//text()", // an XPath query to put into the input box by default - can omit and use "prefill_path_at_cursor": true instead to use the path of the node under the first cursor "live_mode": true, // as per settings "normalize_whitespace_in_preview": false, // as per settings "intelligent_auto_complete": true, // as per settings "goto_element": "names", // same options available as for goto_relative "goto_attribute": "value", // options are name, value, entire "max_results_to_show": 1000 // as per settings }

Br, Toube

keith-hall commented 7 years ago

I just tried putting the following in my Packages/User/Default (Windows).sublime-keymap file and it worked for me:

{ "keys": ["ctrl+shift+alt+q"], "command": "query_xpath", "args": { "prefill_query": "//text()",
    "live_mode": true,
    "normalize_whitespace_in_preview": false,
    "intelligent_auto_complete": true,
    "goto_element": "names",
    "goto_attribute": "value",
    "max_results_to_show": 1000
}}

the differences from yours are:

Does that help? If not, open the ST console and type sublime.log_input(True) Enter and sublime.log_commands(True) Enter and then click back in your XML document and press ctrl+shift+alt+q and check the console. It should show:

key evt: shift+control+alt+q
command: query_xpath {"goto_attribute": "value", "goto_element": "names", "intelligent_auto_complete": true, "live_mode": true, "max_results_to_show": 1000, "normalize_whitespace_in_preview": false, "prefill_query": "//text()"}

if it shows something else, that something else might give us a clue where it is going wrong ;)

Toubef commented 7 years ago

Hi, aah now I get it, I have edited the wrong sublime-keymap settings file :) Edited the right one and now it works. Thanks for your help, appreciated it 👍

Br, Toube