1+ # Sublime Text 3 Plugin
2+ # apiDocAutocompletion adds apiDoc tags to list of code completion suggestions.
3+ # Project: https://github.com/DWand/ST3_apiDocAutocompletion
4+ # License: MIT
5+
6+ import sublime
7+ import sublime_plugin
8+
9+ class apiDocAutocompletion (sublime_plugin .EventListener ):
10+ _suggestions = [
11+ ("@api\t apiDoc" , "@api {${1:method}} ${2:path} ${3:[title]}" ),
12+ ("@apiDefine\t apiDoc" , "@apiDefine ${1:name} ${2:[title]}\n * ${3:[description]}" ),
13+ ("@apiDescription\t apiDoc" , "@apiDescription ${1:text}" ),
14+ ("@apiError\t apiDoc" , "@apiError ${1:[(group)]} ${2:[{type\}]} ${3:field} ${4:[description]}" ),
15+ ("@apiErrorExample\t apiDoc" , "@apiErrorExample ${1:[{type\}]} ${2:[title]}\n * ${3:example}" ),
16+ ("@apiExample\t apiDoc" , "@apiExample ${1:[{type\}]} ${2:title}\n * ${3:example}" ),
17+ ("@apiGroup\t apiDoc" , "@apiGroup ${1:name}" ),
18+ ("@apiHeader\t aiDoc" , "@apiHeader ${1:[(group)]} ${2:[{type\}]} ${3:[field=defaultValue]} ${4:[description]}" ),
19+ ("@apiHeaderExample\t apiDoc" , "@apiHeaderExample ${1:[{type\}]} ${2:[title]}\n * ${3:example}" ),
20+ ("@apiIgnore\t apiDoc" , "@apiIgnore ${1:[hint]}" ),
21+ ("@apiName\t apiDoc" , "@apiName ${1:name}" ),
22+ ("@apiParam\t apiDoc" , "@apiParam ${1:[(group)]} ${2:[{type\}]} ${3:[field=defaultValue]} ${4:[description]}" ),
23+ ("@apiParamExample\t apiDoc" , "@apiParamExample ${1:[{type\}]} ${2:[title]}\n * ${3:example}" ),
24+ ("@apiPermission\t apiDoc" , "@apiPermission ${1:name}" ),
25+ ("@apiSampleRequest\t apiDoc" , "@apiSampleRequest ${1:url}" ),
26+ ("@apiSuccess\t apiDoc" , "@apiSuccess ${1:[(group)]} ${2:[{type\}]} ${3:field} ${4:[description]}" ),
27+ ("@apiSuccessExample\t apiDoc" , "@apiSuccessExample ${1:[{type\}]} ${2:[title]}\n * ${3:example}" ),
28+ ("@apiUse\t apiDoc" , "@apiUse ${1:name}" ),
29+ ("@apiVersion\t apiDoc" , "@apiVersion ${1:version}" ),
30+ ("@apiDefineErrorStructure\t apiDoc [deprecated]" , "@apiDefineErrorStructure ${1:name}" ),
31+ ("@apiDefineHeaderStructure\t apiDoc [deprecated]" , "@apiDefineHeaderStructure ${1:name}" ),
32+ ("@apiDefinePermission\t apiDoc [deprecated]" , "@apiDefinePermission ${1:name} ${2:[title]}\n * ${3:[description]}" ),
33+ ("@apiDefineStructure\t apiDoc [deprecated]" , "@apiDefineStructure ${1:name}" ),
34+ ("@apiDefineSuccessStructure\t apiDoc [deprecated]" , "@apiDefineSuccessStructure ${1:name}" ),
35+ ("@apiErrorStructure\t apiDoc [deprecated]" , "@apiErrorStructure ${1:name}" ),
36+ ("@apiErrorTitle\t apiDoc [deprecated]" , "@apiErrorTitle (${1:group}) ${2:description}" ),
37+ ("@apiGroupDescription\t apiDoc [deprecated]" , "@apiGroupDescription ${1:text}" ),
38+ ("@apiHeaderStructure\t apiDoc [deprecated]" , "@apiHeaderStructure ${1:name}" ),
39+ ("@apiHeaderTitle\t apiDoc [deprecated]" , "@apiHeaderTitle (${1:group}) ${2:description}" ),
40+ ("@apiParamTitle\t apiDoc [deprecated]" , "@apiParamTitle (${1:group}) ${2:description}" ),
41+ ("@apiStructure\t apiDoc [deprecated]" , "@apiStructure ${1:name}" ),
42+ ("@apiSuccessStructure\t apiDoc [deprecated]" , "@apiSuccessStructure ${1:name}" ),
43+ ("@apiSuccessTitle\t apiDoc [deprecated]" , "@apiSuccessTitle (${1:group}) ${2:description}" ),
44+ ]
45+
46+ def on_query_completions (self , view , prefix , locations ):
47+
48+ # Block comment scopes:
49+ # C#:
50+ # source.cs comment.block.source.cs
51+ # Go:
52+ # source.go comment.block.go
53+ # Dart:
54+ # -
55+ # Java:
56+ # source.java comment.block.documentation.javadoc meta.documentation.comment.javadoc text.html
57+ # JavaScript:
58+ # source.js comment.block.documentation.js
59+ # PHP:
60+ # text.html.basic source.php.embedded.block.html comment.block.documentation.phpdoc.php
61+ # CoffeeScript:
62+ # source.coffee comment.block.coffee
63+ # Erlang:
64+ # source.erlang
65+ # Perl:
66+ # source.perl meta.comment.full-line.perl comment.line.number-sign.perl
67+ # source.perl comment.block.documentation.perl
68+ # Python:
69+ # source.python string.quoted.double.block.python
70+ # Ruby:
71+ # source.ruby comment.block.documentation.ruby
72+
73+ target_scopes = [
74+ "comment.block" ,
75+ "source.perl meta.comment.full-line.perl comment.line.number-sign.perl" ,
76+ "source.python string.quoted.double.block.python" ,
77+ "source.erlang"
78+ ]
79+
80+ location = locations [0 ]
81+ current_scope = view .scope_name (location )
82+
83+ if any (scope in current_scope for scope in target_scopes ) == True :
84+ return apiDocAutocompletion ._suggestions
85+ else :
86+ return []
0 commit comments