forked from oldjuanito/VSCodeExtension-PostgreSQL
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b1dfcd
commit 073aa08
Showing
7 changed files
with
94 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
psql -U postgres -f signature.sql -t -o signature.json postgres |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,72 @@ | ||
const sigdatas = require('./signature-data').default | ||
|
||
const parse = sd => { | ||
const regex = /\(([^)]+)\)/ | ||
const matches = regex.exec( sd ) | ||
if ( !matches ) return [] | ||
if ( matches.length < 2 ) return [] | ||
const sps = matches[1] | ||
return sps.split(",").map( sp => ({ label: sp })) | ||
} | ||
const data = require('./signature.json') | ||
|
||
/*const parse = args => { | ||
if ( !args ) return [] | ||
return args.split(",").map( sp => ({ label: sp })) | ||
}*/ | ||
|
||
const signatures = sigdatas.map( sd => { | ||
if ( !sd ) return | ||
if ( sd.length < 2 ) return | ||
const signatures = data.map( sd => { | ||
return { | ||
label: sd[0], | ||
documentation: sd[1], | ||
parameters: parse( sd[0] ) | ||
name: sd.nm, | ||
label: sd.nm + "( " + sd.args + " )", | ||
documentation: sd.nt, | ||
parameters: sd.args.split(",").map( sp => ({ label: sp })) | ||
} | ||
}) | ||
|
||
exports.default = { | ||
provideSignatureHelp: ( doc, pos ) => { | ||
|
||
const text = doc.lineAt( pos.line ).text.substring( 0, pos.character ) | ||
const parts = text.split("(") //text before and after ( | ||
const callLookup = ( code, commas )=>{ | ||
const call = { commas } | ||
let char='', i = code.length-1; | ||
for ( ;i>=0; i-- ){ | ||
char = code[i] | ||
if ( char === ',' ) call.commas++ | ||
if ( char === '(' ) { // first open parenthesis | ||
let rest = code.substring( 0, i ) + "(" | ||
var matches = rest.match( /\S+(?=\()/g ) | ||
if ( matches.length ){ | ||
//last sequence before ( | ||
call.name = matches[ matches.length - 1 ] | ||
} | ||
break | ||
} | ||
} | ||
return call | ||
} | ||
|
||
// walk back (and up) | ||
// find word before first open parenthesis | ||
// also calculate commas before first open parenthesis | ||
// return { word, commas: count } | ||
// NOTE: only for simple cases | ||
const walkbackToCall = ( doc, pos ) => { | ||
|
||
let line = pos.line | ||
let code = doc.lineAt( line ).text | ||
code = code.substring( 0, pos.character ) | ||
|
||
let commas = 0, maxLines = 10, call = { } | ||
|
||
while ( !call.name ) { | ||
call = callLookup( code, commas ) | ||
commas = call.commas | ||
|
||
if ( !parts.length ) return Promise.resolve( null ) | ||
if (call.name) break | ||
if (( line-- < 0 ) || ( maxLines-- < 0 )) break | ||
|
||
const ftext = parts[0] | ||
const fwords = ftext.split(" ") | ||
if ( !fwords.length ) return Promise.resolve( null ) | ||
|
||
const fname = fwords[fwords.length-1]; // last word before '(' | ||
if ( !fname ) return Promise.resolve( null ) | ||
|
||
let activeParameter = 0 | ||
if ( parts.length === 2 ){ | ||
activeParameter = parts[1].split(",").length - 1 | ||
} | ||
code = doc.lineAt( line ).text | ||
} | ||
return call | ||
|
||
} | ||
|
||
exports.default = { | ||
provideSignatureHelp: ( doc, pos ) => { // function called at "(" and "," | ||
|
||
const mask = fname.toUpperCase() | ||
const filtered = signatures.filter( s => ~s.label.toUpperCase().indexOf( mask ) && ( s.parameters.length > activeParameter ) ) | ||
return Promise.resolve( { activeParameter, activeSignature: 0, signatures: filtered } ) | ||
const call = walkbackToCall( doc, pos ) // returns { name: 'token before'} | ||
if ( !call.name ) return Promise.resolve( null ) | ||
const mask = call.name.toLowerCase() | ||
const filtered = signatures.filter( s => ~s.name.indexOf( mask ) && ( s.parameters.length > call.commas ) ) | ||
return Promise.resolve( { activeParameter: call.commas, activeSignature: 0, signatures: filtered } ) | ||
|
||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
With signatures as ( | ||
Select --n.nspname || '.' || | ||
p.proname as nm, --name | ||
pg_catalog.pg_get_function_arguments(p.oid) as "args", | ||
pg_catalog.pg_get_function_result(p.oid) as "ret", --returns | ||
d.description as nt --note | ||
From pg_catalog.pg_proc p | ||
Left Join pg_catalog.pg_namespace n ON n.oid = p.pronamespace | ||
Left Join pg_catalog.pg_description d On p.oid = d.objoid | ||
Where pg_catalog.pg_function_is_visible(p.oid) | ||
And p.prorettype <> 'pg_catalog.trigger'::pg_catalog.regtype | ||
--AND n.nspname <> 'pg_catalog' | ||
--AND n.nspname <> 'information_schema' | ||
Order By 1 | ||
) Select array_to_json( array_agg( s.* ) ) From signatures s; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters