import * as vscode from "vscode" ; import { IArtifactSearchResult , ISearchArtifactParam , SearchType } from "../jdtls/artifactSearcher" ; import { executeJavaLanguageServerCommand , isJavaLangugageServerStarndard } from "../jdtls/commands" ; import { COMMAND_COMPLETION_ITEM_SELECTED , INFO_COMPLETION_ITEM_SELECTED } from "./constants" ; import { IMavenCompletionItemProvider } from "./IArtifactProvider" ; import { getSortText } from "./versionUtils" ; class IndexProvider implements IMavenCompletionItemProvider { public async getGroupIdCandidates ( groupIdHint , artifactIdHint ) { if ( ! isJavaLangugageServerStarndard ( ) ) { return [ ] ; } const searchParam = { searchType : SearchType . identifier , groupId : groupIdHint , artifactId : artifactIdHint } ; const docs = await executeJavaLanguageServerCommand ( "java.maven.searchArtifact" , searchParam ) ; const groupIds = Array . from ( new Set ( docs . map ( doc => doc . groupId ) ) . values ( ) ) ; const commandOnSelection = { title : "selected" , command : COMMAND_COMPLETION_ITEM_SELECTED , arguments : [ { infoName : INFO_COMPLETION_ITEM_SELECTED , completeFor : "groupId" , source : "maven-index" } ] } ; return groupIds . map ( gid => { const item = new vscode . CompletionItem ( gid , vscode . CompletionItemKind . Module ) ; item . insertText = gid ; item . detail = "index" ; item . command = commandOnSelection ; return item ; } ) ; } public async getArtifactIdCandidates ( groupIdHint , artifactIdHint ) { if ( ! isJavaLangugageServerStarndard ( ) ) { return [ ] ; } const searchParam = { searchType : SearchType . identifier , groupId : groupIdHint , artifactId : artifactIdHint } ; const docs = await executeJavaLanguageServerCommand ( "java.maven.searchArtifact" , searchParam ) ; const commandOnSelection = { title : "selected" , command : COMMAND_COMPLETION_ITEM_SELECTED , arguments : [ { infoName : INFO_COMPLETION_ITEM_SELECTED , completeFor : "artifactId" , source : "maven-index" } ] } ; return docs . map ( doc => { const item = new vscode . CompletionItem ( doc . artifactId , vscode . CompletionItemKind . Field ) ; item . insertText = doc . artifactId ; item . detail = `GroupId: ${ doc . groupId }` ; ( item as any ) . data = { groupId : doc . groupId } ; item . command = commandOnSelection ; return item ; } ) ; } public async getVersionCandidates ( groupId , artifactId ) { if ( ! groupId && ! artifactId ) { return [ ] ; } if ( ! isJavaLangugageServerStarndard ( ) ) { return [ ] ; } const searchParam = { searchType : SearchType . identifier , groupId , artifactId } ; const docs = await executeJavaLanguageServerCommand ( "java.maven.searchArtifact" , searchParam ) ; const commandOnSelection = { title : "selected" , command : COMMAND_COMPLETION_ITEM_SELECTED , arguments : [ { infoName : INFO_COMPLETION_ITEM_SELECTED , completeFor : "version" , source : "maven-index" } ] } ; return docs . map ( ( doc ) => { const item = new vscode . CompletionItem ( doc . version , vscode . CompletionItemKind . Constant ) ; item . insertText = doc . version ; item . sortText = getSortText ( doc . version ) ; item . command = commandOnSelection ; return item ; } ) ; } } export const indexProvider = new IndexProvider ( ) ;