Skip to content

Commit

Permalink
fix and improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
komsit37 committed Dec 4, 2019
1 parent ac281df commit 07cf100
Show file tree
Hide file tree
Showing 2 changed files with 235 additions and 54 deletions.
69 changes: 17 additions & 52 deletions goto_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
"scss": "http://devdocs.io/#q=%(scope)s+%(query)s",
"less": "http://devdocs.io/#q=%(scope)s+%(query)s",
"google": "https://google.com/search?q=%(scope)s+%(query)s",
"q": "http://code.kx.com/wiki/Reference/%(query)s",
"Q": "http://code.kx.com/wiki/DotQ/%(query)s",
"python": {
"command": ["python", "-m", "pydoc", "%(query)s"],
"failTest": ".*no Python documentation found for.*",
Expand All @@ -43,36 +41,6 @@
"url": "http://docs.python.org/3/search.html?q=%(query)s"
}
}
substitue_map = {
"q": {
"@": "AtSymbol",
"?": "QuestionSymbol",
"~": "Tilde",
"/": "Slash",
"|": "Bar",
"\\": "BackSlash",
"&": "Ampersand",
"_": "Underscore",
".": "DotSymbol",
"\\:": "BackSlashColon",
"/:": "SlashColon",
"'": "Apostrophe",
"Colon":"Colon",
"$": "DollarSign",
"#": "NumberSign",
"':": "ApostropheColon",
"::": "ColonColon",
"^": "Caret",
"!": "BangSymbol",


":": "Colon",
"0:": "ZeroColon",
"1:": "OneColon",
"2:": "TwoColon",
"1": "One"
}
}

def combineDicts(dictionary1, dictionary2):
new_dict = dictionary1.copy()
Expand All @@ -96,47 +64,44 @@ def run(self, edit):

if location and not location.empty():
q = self.view.substr(location)
scope = self.view.scope_name(location.begin()).rpartition('.')[2].strip()
else:
# if no word, just open the reference card
q = '' #empty query string will open reference card

self.open_doc(q, scope)
scope = self.view.scope_name(location.begin()).rpartition('.')[2].strip()
self.open_doc(q, scope)

def open_doc(self, query, scope):

settings = sublime.load_settings("goto_documentation.sublime-settings")
substitue_map = settings.get('substitute')

# attach the prefix and suffix
query = settings.get('prefix', '') + query + settings.get('suffix', '')

# merge the default docs with the one provided by the user
docs = combineDicts(default_docs, settings.get('docs'))

# we use a temp scope so we don't replace the "real" scope
tscope = scope

if not tscope in docs:
tscope = settings.get('fallback_scope', 'google')
if not scope in docs:
scope = settings.get('fallback_scope', 'google')

if not tscope in docs:
if not scope in docs:
self.show_status("No docs available for the current scope !")
return

if tscope == "q":
print("before " + tscope + ":" + query)
query = query.replace(".", "Dot")
if (tscope in substitue_map and query in substitue_map[tscope]):
query = substitue_map[tscope][query]
if scope == "q":
print("before " + scope + ":" + query)
query = query.lower()

query = query.replace("\\", "") # backslash causes Sublime on OSX to open all available browsers
if ("DotQ" in query):
tscope = "Q"
if ("Dotz" in query):
query = query.lower()
if (scope in substitue_map and query in substitue_map[scope]):
query = substitue_map[scope][query]

print("after " + tscope + ":" + query)
query = query.replace("\\", "") # backslash causes Sublime on OSX to open all available browsers
print("after " + scope + ":" + query)

# if we have the scope defined in settings
# build the url and open it
doc = docs[tscope]
doc = docs[scope]

# if it is a dict we must have:
# - a command to run
Expand Down
220 changes: 218 additions & 2 deletions settings/goto_documentation.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,226 @@
"changeWith": "-------\n\\1",
// fallback url: if failTest returns true this will be used
"url": "http://docs.python.org/3/search.html?q=%(query)s"
}
},
"q": "https://code.kx.com/v2/ref/%(query)s"
},
// if we have no docs for the current scope
// we will try using the fallback one,
// to disable set to false
"fallback_scope": "google"
"fallback_scope": "google",

"substitute": {
//scope to enable substitute
"q": {
//substitute selected text before doc lookup
//overloads
"@": "overloads/#at",
"?": "overloads/#query",
"/": "overloads/#slash",
"\\": "overloads/#backslash",
"_": "overloads/#_-underscore",
".": "overloads/#dot",
"'": "overloads/#quote",
"$": "overloads/#dollar",
"#": "overloads/#hash",
"':": "overloads/#quote-colon",
"!": "overloads/#bang",

"~": "match",
"|": "greater",
"&": "lesser",
",": "join",

"+": "add",
"-": "subtract",
"*": "multiply",
"%": "divide",

"\\:": "maps/#each-left-and-each-right",
"/:": "maps/#each-left-and-each-right",
"::": "identity",
"^": "fill",
"0:": "file-text",
"1:": "file-binary",
"2:": "dynamic-load",

//dotq
".q.a": "dotq/#qa-lowercase-alphabet",
".q.btoa": "dotq/#qbtoa-b64-encode",
".q.a": "dotq/#qa-uppercase-alphabet",
".q.j10": "dotq/#qj10-encode-binhex",
".q.addmonths": "dotq/#qaddmonths",
".q.j12": "dotq/#qj12-encode-base64",
".q.bt": "dotq/#qbt-backtrace",
".q.m": "dotq/#qm-long-infinity",
".q.dd": "dotq/#qdd-join-symbols",
".q.ty": "dotq/#qty-type",
".q.def": "dotq/#qdef",
".q.x10": "dotq/#qx10-decode-binhex",
".q.f": "dotq/#qf-format",
".q.x12": "dotq/#qx12-decode-base64",
".q.fc": "dotq/#qfc-parallel-on-cut",
".q.ff": "dotq/#qff-append-columns",
//database"
".q.fmt": "dotq/#qfmt-format",
".q.chk": "dotq/#qchk-fill-hdb",
".q.ft": "dotq/#qft-apply-simple",
".q.dpft": "dotq/#qdpft-save-table",
".q.fu": "dotq/#qfu-apply-unique",
".q.dpfts": "dotq/#qdpfts-save-table-with-sym",
".q.gc": "dotq/#qgc-garbage-collect",
".q.dsftg": "dotq/#qdsftg-load-process-save",
".q.id": "dotq/#qid-sanitize",
".q.en": "dotq/#qen-enumerate-varchar-cols",
".q.qt": "dotq/#qqt-is-table",
".q.ens": "dotq/#qens-enumerate-against-domain",
".q.res": "dotq/#qres-keywords",
".q.fk": "dotq/#qfk-foreign-key",
".q.s": "dotq/#qs-plain-text",
".q.hdpf": "dotq/#qhdpf-save-tables",
".q.s1": "dotq/#qs1-string-representation",
".q.qt": "dotq/#qqt-is-table",
".q.sbt": "dotq/#qsbt-string-backtrace",
".q.qp": "dotq/#qqp-is-partitioned",
".q.sha1": "dotq/#qsha1-sha-1-encode",
".q.trp": "dotq/#qtrp-extend-trap",
//partitioned-database-state"
".q.ts": "dotq/#qts-time-and-space",
".q.bv": "dotq/#qbv-build-vp",
".q.u": "dotq/#qu-date-based",
".q.cn": "dotq/#qcn-count-partitioned-table",
".q.v": "dotq/#qv-table-to-dict",
".q.d": "dotq/#qd-partitions",
".q.v": "dotq/#qv-value",
".q.ind": "dotq/#qind-partitioned-index",
".q.view": "dotq/#qview-subview",
".q.map": "dotq/#qmap-maps-partitions",
".q.par": "dotq/#qpar-locate-partition",
//environment"
".q.pd": "dotq/#qpd-partition-locations",
".q.k": "dotq/#qk-version",
".q.pd": "dotq/#qpd-modified-partition-locns",
".q.opt": "dotq/#qopt-command-parameters",
".q.pf": "dotq/#qpf-partition-field",
".q.res": "dotq/#qres-k-words",
".q.pn": "dotq/#qpn-partition-counts",
".q.w": "dotq/#qw-memory-stats",
".q.qp": "dotq/#qqp-is-partitioned",
".q.x": "dotq/#qx-non-command-parameters",
".q.pt": "dotq/#qpt-partitioned-tables",
".q.pv": "dotq/#qpv-partition-values",
//ipc"
".q.pv": "dotq/#qpv-modified-partition-values",
".q.addr": "dotq/#qaddr-ip-address",
".q.vp": "dotq/#qvp-missing-partitions",
".q.fps": "dotq/#qfps-streaming-algorithm",
".q.fs": "dotq/#qfs-streaming-algorithm",
//segmented-database-state"
".q.fsn": "dotq/#qfsn-streaming-algorithm",
".q.d": "dotq/#qd-partitions",
".q.hg": "dotq/#qhg-http-get",
".q.p": "dotq/#qp-segments",
".q.host": "dotq/#qhost-hostname",
".q.u": "dotq/#qu-date-based",
".q.hp": "dotq/#qhp-http-post",
".q.l": "dotq/#ql-load",
//file-i/o"
".q.cf": "dotq/#qcf-create-empty-nested-char-file",
".q.xf": "dotq/#qxf-create-file",
//dotz
".z.a": "dotz/#za-ip-address",
".z.ac": "dotz/#zac-http-auth-from-cookie",
".z.b": "dotz/#zb-dependencies",
".z.bm": "dotz/#zbm-msg-validator",
".z.c": "dotz/#zc-cores",
".z.exit": "dotz/#zexit-action-on exit",
".z.d": "dotz/#zd-d-date-shortcuts",
".z.pc": "dotz/#zpc-close",
".z.e": "dotz/#ze-tls-connection-status",
".z.pd": "dotz/#zpd-peach-handles",
".z.ex": "dotz/#zex-failed-primitive",
".z.pg": "dotz/#zpg-get",
".z.ey": "dotz/#zey-arg-to-failed-primitive",
".z.ph": "dotz/#zph-http-get",
".z.f": "dotz/#zf-file",
".z.pi": "dotz/#zpi-input",
".z.h": "dotz/#zh-host",
".z.po": "dotz/#zpo-open",
".z.i": "dotz/#zi-pid",
".z.pp": "dotz/#zpp-http-post",
".z.k": "dotz/#zk-version",
".z.pq": "dotz/#zpq-qcon",
".z.k": "dotz/#zk-release-date",
".z.ps": "dotz/#zps-set",
".z.l": "dotz/#zl-license",
".z.pw": "dotz/#zpw-validate-user",
".z.n": "dotz/#zn-local-timespan",
".z.ts": "dotz/#zts-timer",
".z.o": "dotz/#zo-os-version",
".z.vs": "dotz/#zvs-value-set",
".z.p": "dotz/#zp-local-timestamp",
".z.wc": "dotz/#zwc-websocket-close",
".z.pm": "dotz/#zpm-http-options",
".z.wo": "dotz/#zwo-websocket-open",
".z.q": "dotz/#zq-quiet-mode",
".z.ws": "dotz/#zws-websocket",
".z.s": "dotz/#zs-self",
".z.t": "dotz/#zt-zt-zd-zd-timedate-shortcuts",
".z.d": "dotz/#zt-zt-zd-zd-timedate-shortcuts",
".z.u": "dotz/#zu-user-id",
".z.w": "dotz/#zw-handles",
".z.x": "dotz/#zx-raw-command-line",
".z.z": "dotz/#zz-local-datetime",
".z.zd": "dotz/#zzd-zip-defaults",

//doth
".h.br": "doth/#hbr-linebreak",
".h.hu": "doth/#hhu-uri escape",
".h.c0": "doth/#hc0-web-color",
".h.hug": "doth/#hhug-uri map",
".h.c1": "doth/#hc1-web-color",
".h.hy": "doth/#hhy-http response",
".h.cd": "doth/#hcd-csv-from-data",
".h.HOME": "doth/#hHOME-webserver root",
".h.code": "doth/#hcode-code-after-Tab",
".h.iso8601": "doth/#hiso8601-iso-timestamp",
".h.jx": "doth/#hjx-table",
".h.ed": "doth/#hed-excel-from-data",
".h.logo": "doth/#hlogo-kx-logo",
".h.edsn": "doth/#hedsn-excel-from-tables",
".h.nbr": "doth/#hnbr-no-break",
".h.fram": "doth/#hfram-frame",
".h.pre": "doth/#hpre-pre",
".h.ha": "doth/#hha-anchor",
".h.sa": "doth/#hsa-style",
".h.hb": "doth/#hhb-anchor-target",
".h.sb": "doth/#hsb-style",
".h.hc": "doth/#hhc-escape-lt",
".h.sc": "doth/#hsc-uri-safe",
".h.he": "doth/#hhe-http-400",
".h.td": "doth/#htd-tsv",
".h.hn": "doth/#hhn-http-error",
".h.text": "doth/#htext-paragraphs",
".h.hp": "doth/#hhp-http-response",
".h.tx": "doth/#htx-filetypes",
".h.hr": "doth/#hhr-horizontal-rule",
".h.ty": "doth/#hty-mime-types",
".h.ht": "doth/#hht-marqdown-to-html",
".h.uh": "doth/#huh-uri-unescape",
".h.hta": "doth/#hhta-start-tag",
".h.val": "doth/#hval-value",
".h.htac": "doth/#hhtac-element",
".h.xd": "doth/#hxd-xml",
".h.htc": "doth/#hhtc-element",
".h.xmp": "doth/#hxmp-xmp",
".h.html": "doth/#hhtml-document",
".h.xs": "doth/#hxs-xml-escape",
".h.http": "doth/#hhttp-hyperlinks",
".h.xt": "doth/#hxt-json",

//dotj
".j.j": "dotj/#jj-serialize",
".j.k": "dotj/#jk-deserialize"
}
}
}

0 comments on commit 07cf100

Please sign in to comment.