Skip to content

Commit adc9618

Browse files
committed
试图支持扩展API
1 parent edc488d commit adc9618

File tree

18 files changed

+798
-398
lines changed

18 files changed

+798
-398
lines changed

EmmyLua-Common/src/main/gen/com/tang/intellij/lua/comment/lexer/_LuaDocLexer.java

Lines changed: 370 additions & 365 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

EmmyLua-Common/src/main/gen/com/tang/intellij/lua/comment/parser/LuaDocParser.java

Lines changed: 35 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

EmmyLua-Common/src/main/gen/com/tang/intellij/lua/comment/psi/LuaDocIdField.java

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

EmmyLua-Common/src/main/gen/com/tang/intellij/lua/comment/psi/LuaDocTypes.java

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

EmmyLua-Common/src/main/gen/com/tang/intellij/lua/comment/psi/LuaDocVisitor.java

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

EmmyLua-Common/src/main/gen/com/tang/intellij/lua/comment/psi/impl/LuaDocIdFieldImpl.java

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

EmmyLua-Common/src/main/java/com/tang/intellij/lua/doc.bnf

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989

9090
doc ::= (DASHES after_dash?)*
9191

92-
private after_dash ::= doc_item | STRING { recoverWhile=after_dash_recover }
92+
private after_dash ::= doc_item | doc_field_item | STRING { recoverWhile=after_dash_recover }
9393
private after_dash_recover ::= !(DASHES)
9494
private doc_item ::= '@' (tag_param
9595
| tag_alias
@@ -108,6 +108,7 @@ private doc_item ::= '@' (tag_param
108108
| tag_def
109109
| tag_other
110110
)
111+
private doc_field_item ::= '|' id_field
111112

112113
ty ::= union_ty | function_ty | table_ty | generic_ty | arr_ty | general_ty | par_ty | string_literal_ty {
113114
implements = ['com.tang.intellij.lua.comment.psi.LuaDocType']
@@ -210,6 +211,16 @@ tag_field ::= TAG_NAME_FIELD access_modifier? ((('<' class_name_ref '>')? ID nul
210211
]
211212
}
212213

214+
id_field ::= ID comment_string? {
215+
implements = [
216+
"com.tang.intellij.lua.comment.psi.LuaDocPsiElement"
217+
"com.tang.intellij.lua.psi.LuaClassField"
218+
"com.intellij.psi.PsiNameIdentifierOwner"
219+
]
220+
221+
222+
}
223+
213224
//--- tag
214225
tag_def ::= TAG_NAME_NAME comment_string? {
215226
pin = 1

EmmyLua-Common/src/main/java/com/tang/intellij/lua/doc.flex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ STRING=[^\r\n\t\f]*
4848
ID=[:jletter:] ([:jletterdigit:]|\.)*
4949
NUM=[0-9]+
5050
AT=@
51+
SIMPLE_FIELD=\|
5152
//三个-以上
5253
DOC_DASHES = --+
5354
//Strings
@@ -72,14 +73,14 @@ SINGLE_QUOTED_STRING='([^\\\']|\\\S|\\[\r\n])*'? //'([^\\'\r\n]|\\[^\r\n])*'?
7273
%state xSUPPRESS
7374
%state xDOUBLE_QUOTED_STRING
7475
%state xSINGLE_QUOTED_STRING
75-
7676
%%
7777

7878
<YYINITIAL> {
7979
{EOL} { yybegin(YYINITIAL); return com.intellij.psi.TokenType.WHITE_SPACE;}
8080
{LINE_WS}+ { return com.intellij.psi.TokenType.WHITE_SPACE; }
8181
{DOC_DASHES} { return DASHES; }
8282
"@" { yybegin(xTAG_NAME); return AT; }
83+
"|" { yybegin(xTAG_WITH_ID); return OR; }
8384
. { yybegin(xCOMMENT_STRING); yypushback(yylength()); }
8485
}
8586

EmmyLua-LS/src/main/kotlin/com/tang/vscode/LuaLanguageServer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ class LuaLanguageServer : LanguageServer, LanguageClientAware {
117117
// ),
118118
// true
119119
// )
120+
// capabilities.colorProvider = Either.forLeft(true)
121+
120122
res.capabilities = capabilities
121123
return CompletableFuture.completedFuture(res)
122124
}

EmmyLua-LS/src/main/kotlin/com/tang/vscode/LuaTextDocumentService.kt

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ import com.tang.lsp.getRangeInFile
2323
import com.tang.lsp.nameRange
2424
import com.tang.lsp.toRange
2525
import com.tang.vscode.api.impl.LuaFile
26+
//import com.tang.vscode.color.ColorService
2627
import com.tang.vscode.documentation.LuaDocumentationProvider
28+
import com.tang.vscode.extendApi.ExtendApiService
29+
import com.tang.vscode.extendApi.LuaApiClass
30+
import com.tang.vscode.extendApi.LuaReportApiParams
2731
import com.tang.vscode.formatter.FormattingFormatter
2832
import com.tang.vscode.formatter.FormattingType
2933
import com.tang.vscode.inlayHint.InlayHintService
@@ -62,6 +66,15 @@ class LuaTextDocumentService(private val workspace: LuaWorkspaceService) : TextD
6266
}
6367
}
6468

69+
@Suppress("unused")
70+
@JsonRequest("emmy/reportAPI")
71+
fun reportAPI(params: LuaReportApiParams): CompletableFuture<Boolean> {
72+
return computeAsync { checker->
73+
ExtendApiService.loadApi(params)
74+
true
75+
}
76+
}
77+
6578
private fun findAnnotators(file: ILuaFile): List<Annotator> {
6679
val params = mutableListOf<TextRange>()
6780
val globals = mutableListOf<TextRange>()
@@ -237,32 +250,45 @@ class LuaTextDocumentService(private val workspace: LuaWorkspaceService) : TextD
237250
}
238251
}
239252

240-
override fun documentHighlight(params: DocumentHighlightParams?): CompletableFuture<MutableList<out DocumentHighlight>?> {
253+
override fun documentHighlight(params: DocumentHighlightParams): CompletableFuture<MutableList<out DocumentHighlight>?> {
241254
return computeAsync {
242255
val list = mutableListOf<DocumentHighlight>()
243-
if (params != null) {
244-
withPsiFile(params.textDocument, params.position) { file, psiFile, i ->
245-
val target = TargetElementUtil.findTarget(psiFile, i)
246-
if (target != null) {
247-
val def = target.reference?.resolve() ?: target
248256

249-
// self highlight
250-
if (def.containingFile == psiFile) {
251-
def.nameRange?.let { range -> list.add(DocumentHighlight(range.toRange(file))) }
252-
}
257+
withPsiFile(params.textDocument, params.position) { file, psiFile, i ->
258+
val target = TargetElementUtil.findTarget(psiFile, i)
259+
if (target != null) {
260+
val def = target.reference?.resolve() ?: target
253261

254-
// references highlight
255-
val search = ReferencesSearch.search(def, GlobalSearchScope.fileScope(psiFile))
256-
search.forEach { reference ->
257-
list.add(DocumentHighlight(reference.getRangeInFile(file)))
258-
}
262+
// self highlight
263+
if (def.containingFile == psiFile) {
264+
def.nameRange?.let { range -> list.add(DocumentHighlight(range.toRange(file))) }
265+
}
266+
267+
// references highlight
268+
val search = ReferencesSearch.search(def, GlobalSearchScope.fileScope(psiFile))
269+
search.forEach { reference ->
270+
list.add(DocumentHighlight(reference.getRangeInFile(file)))
259271
}
260272
}
261273
}
274+
262275
list
263276
}
264277
}
265278

279+
// override fun documentColor(params: DocumentColorParams): CompletableFuture<MutableList<ColorInformation>> {
280+
// return computeAsync { checker ->
281+
// val file = workspace.findFile(params.textDocument.uri)
282+
// val list = mutableListOf<ColorInformation>()
283+
// if (file is ILuaFile) {
284+
// file.lock {
285+
// list.addAll(ColorService.renderColor(file, checker))
286+
// }
287+
// }
288+
// list
289+
// }
290+
// }
291+
266292
override fun definition(params: DefinitionParams?): CompletableFuture<Either<MutableList<out Location>, MutableList<out LocationLink>>?> {
267293
return computeAsync {
268294
val list = mutableListOf<Location>()
@@ -371,7 +397,7 @@ class LuaTextDocumentService(private val workspace: LuaWorkspaceService) : TextD
371397
val uri = refFile.uri.toString()
372398
val list = map.getOrPut(uri) { mutableListOf() }
373399
val range = reference.getRangeInFile(refFile);
374-
if(range != refRange) {
400+
if (range != refRange) {
375401
list.add(TextEdit(range, params.newName))
376402
}
377403
}
@@ -418,6 +444,10 @@ class LuaTextDocumentService(private val workspace: LuaWorkspaceService) : TextD
418444
}
419445
}
420446

447+
// override fun colorPresentation(params: ColorPresentationParams): CompletableFuture<MutableList<ColorPresentation>> {
448+
// return super.colorPresentation(params)
449+
// }
450+
421451
override fun documentSymbol(params: DocumentSymbolParams): CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> {
422452
return computeAsync {
423453
val list = mutableListOf<Either<SymbolInformation, DocumentSymbol>>()
@@ -524,6 +554,7 @@ class LuaTextDocumentService(private val workspace: LuaWorkspaceService) : TextD
524554
workspace.removeFileIfNeeded(params.textDocument.uri)
525555
}
526556

557+
// @deprecated please use emmyluaCodeStyle plugin
527558
override fun formatting(params: DocumentFormattingParams?): CompletableFuture<MutableList<out TextEdit>> {
528559
return computeAsync {
529560
val list = mutableListOf<TextEdit>()

0 commit comments

Comments
 (0)