@@ -8,7 +8,7 @@ import "ace-builds/src-noconflict/snippets/javascript"; //代码提示
88
99// https://ace.c9.io/#nav=howto
1010// 初始化
11- export function useInit ( container ) {
11+ export function useInit ( container , type ) {
1212 // 初始化
1313 const target = ace . edit ( container , {
1414 maxLines : 20 , // 最大行数,超过会自动出现滚动条
@@ -25,46 +25,75 @@ export function useInit(container) {
2525 } ) ;
2626
2727 // 自定义提示
28- customCompletions ( target )
28+ customCompletions ( target , type )
2929
3030 return target ;
3131}
3232
3333// 自定义提示
34- function customCompletions ( target ) {
35- target . completers . push ( {
36- getCompletions : function ( state , session , pos , prefix , callback ) {
37- if ( prefix . length === 0 ) {
38- callback ( null , [ ] ) ;
39- return ;
40- }
41- callback ( null , [
42- { meta : 'AjaxProxy::Ctx.req' , caption : 'req.url: string' , value : 'req.url' , score : 100 } ,
43- { meta : 'AjaxProxy::Ctx.req' , caption : 'req.method: string' , value : 'req.method' , score : 100 } ,
44- { meta : 'AjaxProxy::Ctx.req' , caption : 'req.body?: any' , value : 'req.body' , score : 100 } ,
45- { meta : 'AjaxProxy::Ctx.res' , caption : 'res.status: string' , value : 'res.status' , score : 100 } ,
46- { meta : 'AjaxProxy::Ctx.res' , caption : 'res.customStatus: string' , value : 'res.customStatus' , score : 100 } ,
47- { meta : 'AjaxProxy::Ctx.res' , caption : 'res.response: any' , value : 'res.response' , score : 100 } ,
48- {
49- meta : 'AjaxProxy::Next' ,
50- caption : 'next({ override?: string, status?: string | number })' ,
51- value : 'next({ override: "", status: "" });' ,
52- score : 100
53- } ,
54- ] ) ;
55- } ,
56- } ) ;
34+ function customCompletions ( target , type = 'interceptor' ) {
35+ if ( type === 'interceptor' )
36+ target . completers . push ( {
37+ getCompletions : function ( state , session , pos , prefix , callback ) {
38+ if ( prefix . length === 0 ) {
39+ callback ( null , [ ] ) ;
40+ return ;
41+ }
42+ callback ( null , [
43+ { meta : 'AjaxProxy::Ctx.req' , caption : 'req.url: string' , value : 'req.url' , score : 100 } ,
44+ { meta : 'AjaxProxy::Ctx.req' , caption : 'req.method: string' , value : 'req.method' , score : 100 } ,
45+ { meta : 'AjaxProxy::Ctx.req' , caption : 'req.body?: any' , value : 'req.body' , score : 100 } ,
46+ { meta : 'AjaxProxy::Ctx.res' , caption : 'res.status: string' , value : 'res.status' , score : 100 } ,
47+ { meta : 'AjaxProxy::Ctx.res' , caption : 'res.customStatus: string' , value : 'res.customStatus' , score : 100 } ,
48+ { meta : 'AjaxProxy::Ctx.res' , caption : 'res.response: any' , value : 'res.response' , score : 100 } ,
49+ {
50+ meta : 'AjaxProxy::Next' ,
51+ caption : 'next({ override?: string, status?: string | number })' ,
52+ value : 'next({ override: "", status: "" });' ,
53+ score : 100
54+ } ,
55+ ] ) ;
56+ } ,
57+ } ) ;
58+ else
59+ target . completers . push ( {
60+ getCompletions : function ( state , session , pos , prefix , callback ) {
61+ if ( prefix . length === 0 ) {
62+ callback ( null , [ ] ) ;
63+ return ;
64+ }
65+ callback ( null , [
66+ { meta : 'AjaxProxy::Ctx.req' , caption : 'req.url: string' , value : 'req.url' , score : 100 } ,
67+ { meta : 'AjaxProxy::Ctx.req' , caption : 'req.method: string' , value : 'req.method' , score : 100 } ,
68+ {
69+ meta : 'AjaxProxy::Next' ,
70+ caption : 'next({ url: string, headers?: { [key: string]: string } })' ,
71+ value : 'next({ url: req.url });' ,
72+ score : 100
73+ } ,
74+ ] ) ;
75+ } ,
76+ } ) ;
5777}
5878
5979// 默认内容
60- export function getDefaultContent ( ) {
61- const defaultContent =
80+ export function getDefaultContent ( type = "interceptor" ) {
81+ let defaultContent = type === 'interceptor' ?
6282 `
6383function setup(req, res, next) {
6484 // TODO...
6585 // type Next = { override?: string, status?: string | number }
6686 next({ override: "", status: "" });
6787}
88+ ` :
89+ `
90+ function setup(
91+ req, /** req: { url: string, method: string }*/
92+ next /**{ url: string, headers?: { [key: string]: string } }*/
93+ ) {
94+ // TODO...
95+ next({ url: "" });
96+ }
6897`
6998 return defaultContent
7099}
0 commit comments