Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
paxtonhare committed Dec 20, 2016
2 parents 7719d32 + f4b8552 commit ede8329
Show file tree
Hide file tree
Showing 28 changed files with 258 additions and 291 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# http://editorconfig.org
root = true

[*]
indent_style = tab
indent_size = 2
end_of_line = lf
charset = utf-8
insert_final_newline = true
6 changes: 4 additions & 2 deletions MarkLogic.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"ml_host": "localhost",

// Xcc port to communicate with for running queries
"xcc_port": "8041",
"xcc_port": "8000",

// The content database to use when evaluating queries
"content_database": "Documents",
Expand Down Expand Up @@ -73,5 +73,7 @@
},

// enables debugging output in the console window (ctrl + ` to open console)
"debug": false
"debug": false,

"ml_version": 8
}
8 changes: 5 additions & 3 deletions dynamic_snippets/imports.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
{"content": "import module namespace dls = \"http://marklogic.com/xdmp/dls\"\n\tat \"/MarkLogic/dls.xqy\";\n", "trigger": "dls", "scope": "source.xquery-ml", "description": "import dls"},
{"content": "import module namespace dom = \"http://marklogic.com/cpf/domains\"\n\tat \"/MarkLogic/cpf/domains.xqy\";\n", "trigger": "dom", "scope": "source.xquery-ml", "description": "import dom"},
{"content": "import module namespace entity = \"http://marklogic.com/entity\"\n\tat \"/MarkLogic/entity.xqy\";\n", "trigger": "entity", "scope": "source.xquery-ml", "description": "import entity"},
{"content": "import module namespace es = \"http://marklogic.com/entity-services\"\n\tat \"/MarkLogic/entity-services/entity-services.xqy\";\n", "trigger": "es", "scope": "source.xquery-ml", "description": "import entity-services"},
{"content": "import module namespace excel = \"http://marklogic.com/cpf/excel\"\n\tat \"/MarkLogic/conversion/excel.xqy\";\n", "trigger": "excel", "scope": "source.xquery-ml", "description": "import excel"},
{"content": "import module namespace flexrep = \"http://marklogic.com/xdmp/flexible-replication\"\n\tat \"/MarkLogic/flexrep.xqy\";\n", "trigger": "flexrep", "scope": "source.xquery-ml", "description": "import flexrep"},
{"content": "import module namespace functx = \"http://www.functx.com\"\n\tat \"/MarkLogic/functx/functx-1.0-nodoc-2007-01.xqy\";\n", "trigger": "functx", "scope": "source.xquery-ml", "description": "import functx"},
{"content": "import module namespace geo = \"http://marklogic.com/geospatial\"\n\tat \"/MarkLogic/geospatial/geospatial.xqy\";\n", "trigger": "geo", "scope": "source.xquery-ml", "description": "import geo"},
{"content": "import module namespace geojson = \"http://marklogic.com/geospatial/geojson\"\n\tat \"/MarkLogic/geospatial/geojson.xqy\";\n", "trigger": "geojson", "scope": "source.xquery-ml", "description": "import geojson"},
{"content": "import module namespace georss = \"http://www.georss.org/georss\"\n\tat \"/MarkLogic/geospatial/georss.xqy\";\n", "trigger": "georss", "scope": "source.xquery-ml", "description": "import georss"},
{"content": "import module namespace gml = \"http://www.opengis.net/gml\"\n\tat \"/MarkLogic/geospatial/gml.xqy\";\n", "trigger": "gml", "scope": "source.xquery-ml", "description": "import gml"},
{"content": "import module namespace geogml = \"http://marklogic.com/geospatial/gml\"\n\tat \"/MarkLogic/geospatial/gml.xqy\";\n", "trigger": "gml", "scope": "source.xquery-ml", "description": "import gml"},
{"content": "import module namespace geokml = \"http://marklogic.com/geospatial/kml\"\n\tat \"/MarkLogic/geospatial/kml.xqy\";\n", "trigger": "kml", "scope": "source.xquery-ml", "description": "import kml"},
{"content": "import module namespace hadoop = \"http://marklogic.com/hadoop\"\n\t at \"/MarkLogic/openxml/hadoop.xqy\";\n", "trigger": "hadoop", "scope": "source.xquery-ml", "description": "import hadoop"},
{"content": "import module namespace info = \"http://marklogic.com/appservices/infostudio\"\n\tat \"/MarkLogic/appservices/infostudio/info.xqy\";\n", "trigger": "info", "scope": "source.xquery-ml", "description": "import info"},
{"content": "import module namespace infodev = \"http://marklogic.com/appservices/infostudio/dev\"\n\t at \"/MarkLogic/appservices/infostudio/infodev.xqy\";\n", "trigger": "infodev", "scope": "source.xquery-ml", "description": "import infodev"},
{"content": "import module namespace json = \"http://marklogic.com/xdmp/json\"\n\tat \"/MarkLogic/json/json.xqy\";\n", "trigger": "json", "scope": "source.xquery-ml", "description": "import json"},
{"content": "import module namespace kml = \"http://earth.google.com/kml/2.0\"\n\tat \"/MarkLogic/geospatial/kml.xqy\";\n", "trigger": "kml", "scope": "source.xquery-ml", "description": "import kml"},
{"content": "import module namespace lnk = \"http://marklogic.com/cpf/links\"\n\tat \"/MarkLogic/cpf/links.xqy\";\n", "trigger": "lnk", "scope": "source.xquery-ml", "description": "import lnk"},
{"content": "import module namespace mcgm = \"http://marklogic.com/geospatial/mcgm\"\n\tat \"/MarkLogic/geospatial/mcgm.xqy\";\n", "trigger": "mcgm", "scope": "source.xquery-ml", "description": "import mcgm"},
{"content": "import module namespace msword = \"http://marklogic.com/cpf/msword\"\n\tat \"/MarkLogic/conversion/msword.xqy\";\n", "trigger": "msword", "scope": "source.xquery-ml", "description": "import msword"},
Expand All @@ -42,4 +44,4 @@
{"content": "import module namespace xhtml = \"http://marklogic.com/cpf/xhtml\"\n\tat \"/MarkLogic/conversion/xhtml.xqy\";\n", "trigger": "xhtml", "scope": "source.xquery-ml", "description": "import xhtml"},
{"content": "import module namespace xinc = \"http://marklogic.com/xinclude\"\n\tat \"/MarkLogic/xinclude/xinclude.xqy\";\n", "trigger": "xinc", "scope": "source.xquery-ml", "description": "import xinc"},
{"content": "import module namespace xp = \"http://marklogic.com/xinclude/xpointer\"\n\tat \"/MarkLogic/xinclude/xpointer.xqy\";\n", "trigger": "xinc", "scope": "source.xquery-ml", "description": "import xinc"}
]
]
1 change: 1 addition & 0 deletions marklogic_builtins/ml-javascript-functions-7.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions marklogic_builtins/ml-javascript-functions-8.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions marklogic_builtins/ml-javascript-functions-9.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion marklogic_builtins/ml-javascript-functions.json

This file was deleted.

1 change: 1 addition & 0 deletions marklogic_builtins/ml-xquery-functions-7.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions marklogic_builtins/ml-xquery-functions-8.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions marklogic_builtins/ml-xquery-functions-9.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion marklogic_builtins/ml-xquery-functions.json

This file was deleted.

5 changes: 3 additions & 2 deletions messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"1.1.6": "messages/1.1.6.txt",
"1.1.7": "messages/1.1.7.txt",
"1.1.8": "messages/1.1.8.txt",
"1.1.9": "messages/1.1.9.txt"
}
"1.1.9": "messages/1.1.9.txt",
"1.2.0": "messages/1.2.0.txt"
}
4 changes: 4 additions & 0 deletions messages/1.2.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MarkLogic Sublime Plugin 1.2.0
----------------------------
- Updated syntax to work with MarkLogic 9.0 EA
- fixed issue with multiline comments #38
3 changes: 2 additions & 1 deletion ml/commands/list_databases_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ def run(self):
xcc = Xcc()
resp = xcc.run_query("""
fn:string-join(xdmp:databases() ! xdmp:database-name(.), ",")
""")
""",
"xquery", False, True)
self.dbs = resp.split(',')
self.window.show_quick_panel(self.dbs, self.on_done)

Expand Down
10 changes: 6 additions & 4 deletions ml/commands/mark_logic_auto_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,21 @@ def process_included_code_snippets(self, view, prefix, completions):

if (file_name):
for other_file, ns_prefix in MlUtils.get_imported_files(file_name, contents):
with open(other_file, "r") as myfile:
with open(other_file, "r", encoding='utf-8') as myfile:
buffer = myfile.read()
self.snippets_from_xqy_file(other_file, buffer, ns_prefix, False, prefix, completions)

# called when Sublime wants a list of autocompletes
def on_query_completions(self, view, prefix, locations):
completions = []

version = str(MlSettings.ml_version())
if view.match_selector(locations[0], "source.xquery-ml"):
self.process_dynamic_snippets(view, prefix, completions)
self.process_function_snippets(view, prefix, self.xquery_function_snippets, 'ml-xquery-functions.json', completions)
snippets_file = "ml-xquery-functions-" + version + ".json"
self.process_function_snippets(view, prefix, self.xquery_function_snippets, snippets_file, completions)
self.process_included_code_snippets(view, prefix, completions)
elif MlUtils.is_server_side_js(view):
self.process_function_snippets(view, prefix, self.javascript_function_snippets, 'ml-javascript-functions.json', completions)
self.process_function_snippets(view, prefix, self.javascript_function_snippets, "ml-javascript-functions-" + version + ".json", completions)

return completions
return completions
23 changes: 18 additions & 5 deletions ml/commands/ml_lint_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def run(self, edit, show_regions=True, show_panel=True):
return

contents = self.view.substr(sublime.Region(0, self.view.size()))
is_module = self.is_module(contents)
sans_comments = self.strip_comments(contents)
is_module = self.is_module(sans_comments)

try:
xcc = Xcc()
Expand All @@ -49,7 +50,7 @@ def run(self, edit, show_regions=True, show_panel=True):

if is_module:
xcc.insert_file('/_ml_sublime_lint_me.xqy', contents)
namespace = self.get_module_ns(contents)
namespace = self.get_module_ns(sans_comments)
contents = re.sub(r'_PUT_MOD_NS_HERE_', namespace, self.lint_xqy)

resp = xcc.run_query(contents, query_type, not is_module)
Expand Down Expand Up @@ -130,9 +131,21 @@ def error_location(self, s):

return (description, line, column)

def strip_comments(self, s):
chars = len(s)
sans_comments = ""
comment_start = 0
for i in range(0, chars):
if (s[i] == "(" and s[i + 1] == ":"):
comment_start = comment_start + 1
elif (i > 0 and s[i - 1] == ":" and s[i] == ")"):
comment_start = comment_start - 1
elif (comment_start == 0):
sans_comments += s[i]
return sans_comments

def is_module(self, s):
sans_comments = re.sub(r"\(:.*?:\)", "", s)
return re.search(r"[\r\n\s]*xquery[^'\"]+(['\"])[^'\"]+?\1;?[\r\n\s]+module", sans_comments, re.DOTALL | re.M) != None
return re.search(r"[\r\n\s]*xquery[^'\"]+(['\"])[^'\"]+?\1;?[\r\n\s]+module", s, re.DOTALL | re.M) != None

def get_module_ns(self, contents):
search = re.search(r"""^\s*module\s+namespace\s+[^\s]+\s*=\s*['"]([^"']+)""", contents, re.MULTILINE)
Expand Down Expand Up @@ -180,4 +193,4 @@ def on_quick_panel_selection(self, index):
return

self.view.erase_regions("marklogic_lint_selected")
self.view.add_regions("marklogic_lint_selected", [region], "meta")
self.view.add_regions("marklogic_lint_selected", [region], "meta")
3 changes: 2 additions & 1 deletion ml/commands/ml_set_content_database_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def run(self):
xcc = Xcc()
resp = xcc.run_query("""
fn:string-join(xdmp:databases() ! xdmp:database-name(.), ",")
""")
""",
"xquery", False, True)
self.dbs = resp.split(',')
self.window.show_quick_panel(self.dbs, self.on_done)
except Exception as e:
Expand Down
3 changes: 2 additions & 1 deletion ml/commands/ml_set_modules_database_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def run(self):
xcc = Xcc()
resp = xcc.run_query("""
fn:string-join(xdmp:databases() ! xdmp:database-name(.), ",")
""")
""",
"xquery", False, True)
self.dbs = resp.split(',')
self.window.show_quick_panel(self.dbs, self.on_done)
except Exception as e:
Expand Down
4 changes: 4 additions & 0 deletions ml/ml_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ def get_current_options_file(self):

return os.path.join(sublime.packages_path(), "User", SETTINGS_FILE)

@staticmethod
def ml_version():
return MlSettings.settings().get("ml_version")

@staticmethod
def debug():
return MlSettings.settings().get("debug") == True
Expand Down
10 changes: 5 additions & 5 deletions ml/xcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Xcc():
def __init__(self):
self.settings = {
"ml_host": "localhost",
"xcc_port": "8040",
"xcc_port": "8000",
"content_database": "Documents",
"modules_database": "Modules",
"user": "admin",
Expand Down Expand Up @@ -102,13 +102,13 @@ def get_header(self, response, header):
def fix_entity_refs(self, query):
return '&'.join(query.split('&'))

def run_query(self, query, query_type="xquery", check=False):
if ("content_database" in self.settings):
def run_query(self, query, query_type="xquery", check=False, skip_dbs=False):
if (skip_dbs == False and "content_database" in self.settings):
content_db = self.settings["content_database"]
else:
content_db = None

if ("modules_database" in self.settings):
if (skip_dbs == False and "modules_database" in self.settings):
modules_db = self.settings["modules_database"]
else:
modules_db = None
Expand Down Expand Up @@ -220,4 +220,4 @@ def insert_file(self, uri, file_contents):
try:
response = self.http(url, self.settings["user"], self.settings["password"], file_contents, "PUT", headers)
except HTTPError as e:
return e.read().decode("utf-8")
return e.read().decode("utf-8")
146 changes: 146 additions & 0 deletions support/build-functions.xqy
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
(:
: Builds the xquery typeahead completion files. One for each version
: 7-9
:)
declare namespace apidoc = "http://marklogic.com/xdmp/apidoc";

import module namespace json = "http://marklogic.com/xdmp/json"
at "/MarkLogic/json/json.xqy";

declare function local:camel-case(
$str as xs:string) as xs:string
{
if( fn:contains($str , "-" ) ) then
let $subs := fn:tokenize($str,"-")
return
fn:string-join((
$subs[1],
for $s in $subs[ fn:position() gt 1 ]
return (
fn:upper-case( fn:substring($s , 1 , 1 )) , fn:lower-case(fn:substring($s,2)))),"")
else $str
};

declare function local:get-type($param-type as xs:string, $code-type)
{
if ($code-type = "xquery") then
$param-type
else
switch ($param-type)
case "xs:string" return
"String"
case "xs:boolean" return
"Boolean"
default return
$param-type
};

declare function local:dump-funcs(
$module as element(apidoc:module),
$type as xs:string)
{
let $functions :=
for $func in $module/apidoc:function[
(fn:string-length(@name) > 0) and
($type = "xquery" or ($type = "javascript" and fn:not(@class eq "xquery"))) and
fn:not(fn:starts-with(@name, "/"))
]
let $name :=
let $prefix := $func/@lib
let $local-name :=
if ($type = "javascript") then
local:camel-case($func/@name)
else
$func/@name
let $joiner :=
if ($type = "xquery") then ":"
else "."
return
$prefix || $joiner || $local-name
let $params := $func/apidoc:params/apidoc:param[fn:not(@class) or @class = $type]
let $optional-count := fn:count($params[@optional = fn:true()])
let $param-count := fn:count($params)
let $final-params :=
for $param in $func/apidoc:params/apidoc:param[fn:not(@class) or @class = $type]
let $param-type := local:get-type($param/@type, $type)
let $prefix :=
if ($type eq "xquery") then
"$"
else ()
return
$prefix || $param/@name || " as " || $param-type
for $i in fn:reverse(0 to $optional-count)
let $content :=
let $params :=
for $p at $idx in fn:subsequence($final-params, 1, $param-count - $i)
let $p :=
if ($type = "xquery") then
"\" || $p
else
$p
return
"${" || $idx || ":" || $p || "}"
return
$name || "(" || fn:string-join($params, ", ") || ")"
let $trigger := $name
let $desc as xs:string? := "(" || fn:string-join(fn:subsequence($final-params, 1, $param-count - $i), ", ") || ")"
return
object-node {
"content": $content,
"trigger": $trigger,
"description": $desc
}
return
$functions
};

declare function local:dump-em($ml-version, $dir, $output-dir)
{
for $type in ("xquery", "javascript")
let $uri :=
if ($type = "xquery") then
$output-dir || "ml-xquery-functions-" || $ml-version || ".json"
else
$output-dir || "ml-javascript-functions-" || $ml-version || ".json"
let $funcs :=
for $file as xs:string in (xdmp:filesystem-directory($dir)/dir:entry/dir:pathname)
let $module := xdmp:document-get($file)/apidoc:module
return
local:dump-funcs($module, $type)
let $array := xdmp:to-json(json:to-array($funcs))
return
xdmp:save($uri, document { $array }, <options xmlns="xdmp:save"><media-type>application/json</media-type></options>)
};

(:
The directory where you have downloaded the MarkLogic_x.pub.zip files
ex:
let $dir-containing-pub-zips := "/Users/username/Downloads/"
:)
let $dir-containing-pub-zips :=

(:
The directory where your sublime plugin code lives.
ex:
let $output-dir := "/Users/username/src/MarkLogic-Sublime/marklogic_builtins/"
:)
let $output-dir :=


for $version in (7 to 9)
let $file := $dir-containing-pub-zips || "MarkLogic_" || $version || "_pubs.zip"
let $zip := xdmp:document-get($file)/binary()
for $type in ("xquery", "javascript")
let $uri :=
if ($type = "xquery") then
$output-dir || "ml-xquery-functions-" || $version || ".json"
else
$output-dir || "ml-javascript-functions-" || $version || ".json"
let $funcs :=
for $name as xs:string in (xdmp:zip-manifest($zip)/*:part[fn:matches(., "pubs/raw/apidoc/.+\.xml")])
let $module := xdmp:zip-get($zip, $name, <options xmlns="xdmp:zip-get"><format>xml</format></options>)/apidoc:module
return
local:dump-funcs($module, $type)
let $array := xdmp:to-json(json:to-array($funcs))
return
xdmp:save($uri, document { $array }, <options xmlns="xdmp:save"><media-type>application/json</media-type></options>)
Loading

0 comments on commit ede8329

Please sign in to comment.