@Override public boolean process(@NotNull String name, @NotNull GoNamedElement element, @NotNull ExistingImportData importData, @NotNull CompletionResultSet result) { GoFunctionDeclaration function = (GoFunctionDeclaration)element; double priority = importData.exists ? GoCompletionUtil.FUNCTION_PRIORITY : GoCompletionUtil.NOT_IMPORTED_FUNCTION_PRIORITY; result.addElement(GoCompletionUtil.createFunctionOrMethodLookupElement(function, replacePackageWithAlias(name, importData.alias), GoAutoImportInsertHandler.FUNCTION_INSERT_HANDLER, priority)); return true; }
@Override public boolean process(@NotNull String name, @NotNull GoNamedElement element, @NotNull ExistingImportData importData, @NotNull CompletionResultSet result) { double priority = importData.exists ? GoCompletionUtil.VAR_PRIORITY : GoCompletionUtil.NOT_IMPORTED_VAR_PRIORITY; result.addElement(GoCompletionUtil.createVariableLikeLookupElement(element, replacePackageWithAlias(name, importData.alias), GoAutoImportInsertHandler.SIMPLE_INSERT_HANDLER, priority)); return true; }
@Override protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) { for (String keyword : myKeywords) { result.addElement(createKeywordLookupElement(keyword)); } }
private static void addElement(@NotNull PsiElement o, @NotNull ResolveState state, boolean forTypes, boolean vendoringEnabled, @NotNull Set<String> processedNames, @NotNull CompletionResultSet set) { LookupElement lookup = createLookupElement(o, state, forTypes, vendoringEnabled); if (lookup != null) { String lookupString = lookup.getLookupString(); if (!processedNames.contains(lookupString)) { set.addElement(lookup); processedNames.add(lookupString); } } }
@Override public boolean process(@NotNull String name, @NotNull GoNamedElement element, @NotNull ExistingImportData importData, @NotNull CompletionResultSet result) { GoTypeSpec spec = (GoTypeSpec)element; boolean forTypes = myParent instanceof GoTypeReferenceExpression; double priority; if (importData.exists) { priority = forTypes ? GoCompletionUtil.TYPE_PRIORITY : GoCompletionUtil.TYPE_CONVERSION; } else { priority = forTypes ? GoCompletionUtil.NOT_IMPORTED_TYPE_PRIORITY : GoCompletionUtil.NOT_IMPORTED_TYPE_CONVERSION; } String lookupString = replacePackageWithAlias(name, importData.alias); if (forTypes) { result.addElement(GoCompletionUtil.createTypeLookupElement(spec, lookupString, GoAutoImportInsertHandler.SIMPLE_INSERT_HANDLER, importData.importPath, priority)); } else { result.addElement(GoCompletionUtil.createTypeConversionLookupElement(spec, lookupString, GoAutoImportInsertHandler.TYPE_CONVERSION_INSERT_HANDLER, importData.importPath, priority)); } return true; }
private static void addLookupElement(@NotNull String lookupString, int initialPriority, @NotNull Set<String> allTestFunctionNames, @NotNull CompletionResultSet result) { int priority = initialPriority; if (allTestFunctionNames.contains(lookupString)) { priority -= 5; lookupString = UniqueNameGenerator.generateUniqueName(lookupString, allTestFunctionNames); } result.addElement(PrioritizedLookupElement.withPriority(LookupElementBuilder.create(lookupString) .withInsertHandler(GenerateTestInsertHandler.INSTANCE), priority)); }
private void addDirectories(@NotNull CompletionResultSet result, @NotNull String root, @NotNull VirtualFile directory) { VirtualFile[] children = directory.getChildren(); for (VirtualFile child : children) { if (child.isDirectory()) { if (child.getName().startsWith(".")) { continue; } // Path delimiter will be '/' on Linux and Windows OS. String relativePath = child.getPath().replaceFirst(root + File.separator, ""); result.addElement(LookupElementBuilder.create(relativePath)); addDirectories(result, root, child); } } } }
@Override public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) { super.fillCompletionVariants(parameters, result); PsiElement position = parameters.getPosition(); if (insideGoOrDeferStatements().accepts(position) || anonymousFunction().accepts(position)) { InsertHandler<LookupElement> insertHandler = GoKeywordCompletionProvider.createTemplateBasedInsertHandler("go_lang_anonymous_func"); result.addElement(GoKeywordCompletionProvider.createKeywordLookupElement("func", CONTEXT_KEYWORD_PRIORITY, insertHandler)); } if (referenceExpression().accepts(position)) { InsertHandler<LookupElement> insertHandler = GoKeywordCompletionProvider.createTemplateBasedInsertHandler("go_lang_anonymous_struct"); result.addElement(GoKeywordCompletionProvider.createKeywordLookupElement("struct", CONTEXT_KEYWORD_PRIORITY, insertHandler)); } }
@Override public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) { PsiElement position = parameters.getPosition(); PsiFile file = parameters.getOriginalFile(); ASTNode node = position.getNode(); if (file instanceof GoFile && position.getParent() instanceof GoPackageClause && node.getElementType() == GoTypes.IDENTIFIER) { boolean isTestFile = GoTestFinder.isTestFile(file); PsiDirectory directory = file.getParent(); String currentPackageName = ((GoFile)file).getPackageName(); Collection<String> packagesInDirectory = GoPackageUtil.getAllPackagesInDirectory(directory, null, true); for (String packageName : packagesInDirectory) { if (!packageName.equals(currentPackageName)) { result.addElement(packageLookup(packageName, GoCompletionUtil.PACKAGE_PRIORITY - 1)); } if (isTestFile) { result.addElement(packageLookup(packageName + GoConstants.TEST_SUFFIX, GoCompletionUtil.PACKAGE_PRIORITY)); } } if (directory != null && ContainerUtil.filter(directory.getFiles(), Conditions.instanceOf(GoFile.class)).size() == 1) { String packageFromDirectory = GoPsiImplUtil.getLocalPackageName(directory.getName()); if (!packageFromDirectory.isEmpty()) { result.addElement(packageLookup(packageFromDirectory, GoCompletionUtil.PACKAGE_PRIORITY - 1)); } } result.addElement(packageLookup(GoConstants.MAIN, GoCompletionUtil.PACKAGE_PRIORITY - 2)); } super.fillCompletionVariants(parameters, result); }
private void processParameterList(@NotNull List<BallerinaParameter> parameterList) { for (BallerinaParameter parameter : parameterList) { List<BallerinaParameterWithType> parameterWithTypeList = parameter.getParameterWithTypeList(); for (BallerinaParameterWithType ballerinaParameterWithType : parameterWithTypeList) { PsiElement identifier = ballerinaParameterWithType.getIdentifier(); if (identifier == null) { continue; } if (myResult != null) { myResult.addElement(BallerinaCompletionUtils.createParameterLookupElement(identifier, BallerinaPsiImplUtil.formatBallerinaTypeName(ballerinaParameterWithType.getTypeName()), null)); } else if (myElement.getText().equals(identifier.getText())) { add(identifier); } } } }
public static void addCompletions(@NotNull CompletionResultSet result, @NotNull Module module, @Nullable PsiElement context, @NotNull GlobalSearchScope scope, boolean allowMain) { Project project = module.getProject(); boolean vendoringEnabled = GoVendoringUtil.isVendoringEnabled(module); String contextImportPath = GoCompletionUtil.getContextImportPath(context, vendoringEnabled); GoExcludedPathsSettings excludedSettings = GoExcludedPathsSettings.getInstance(project); PsiFile contextFile = context != null ? context.getContainingFile() : null; boolean testFileWithTestPackage = GoTestFinder.isTestFileWithTestPackage(contextFile); for (VirtualFile file : FileTypeIndex.getFiles(GoFileType.INSTANCE, scope)) { ProgressManager.checkCanceled(); PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (!(psiFile instanceof GoFile)) continue; PsiDirectory directory = psiFile.getContainingDirectory(); if (directory == null) continue; GoFile goFile = (GoFile)psiFile; if (!GoPsiImplUtil.canBeAutoImported(goFile, allowMain, module)) continue; String importPath = goFile.getImportPath(vendoringEnabled); if (StringUtil.isNotEmpty(importPath) && !excludedSettings.isExcluded(importPath) && (testFileWithTestPackage || !importPath.equals(contextImportPath))) { result.addElement(GoCompletionUtil.createPackageLookupElement(importPath, contextImportPath, directory, false)); } } } }
myResult.addElement(BallerinaCompletionUtils.createFieldLookupElement( definitionIdentifier, identifier, typeName, null, null, false, false)); } else if (myElement.getText().equals(definitionIdentifier.getText())) { myResult.addElement(BallerinaCompletionUtils.createFunctionLookupElement( functionDefinition, identifier, SmartParenthesisInsertHandler.INSTANCE)); } else if (myElement.getText().equals(identifier.getText())) {
@Override public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) { ProgressManager.checkCanceled(); if (accept(element)) { List<BallerinaDefinition> definitions = ((BallerinaFile) element).getDefinitions(); for (BallerinaDefinition definition : definitions) { ProgressManager.checkCanceled(); PsiElement lastChild = definition.getLastChild(); if (lastChild instanceof BallerinaDefinition) { lastChild = lastChild.getLastChild(); } if (lastChild instanceof BallerinaTypeDefinition) { BallerinaTypeDefinition child = (BallerinaTypeDefinition) lastChild; PsiElement identifier = child.getIdentifier(); if (identifier != null) { if (myResult != null) { myResult.addElement(BallerinaCompletionUtils.createTypeLookupElement(child)); } else if (myElement.getText().equals(identifier.getText())) { add(identifier); } } } } } return true; }
myResult.addElement(BallerinaCompletionUtils.createParameterLookupElement(identifier, null, null)); } else if (myElement.getText().equals(identifier.getText())) { add(identifier); if (identifier != null) { if (myResult != null) { myResult.addElement(BallerinaCompletionUtils.createParameterLookupElement(identifier, null, null)); } else if (myElement.getText().equals(identifier.getText())) { add(identifier);
continue; myResult.addElement(BallerinaCompletionUtils.createFunctionLookupElement (objectFunctionDefinition, owner, SmartParenthesisInsertHandler.INSTANCE)); } else if (myElement.getText().equals(identifier.getText())) {
if (identifier != null) { if (myResult != null) { myResult.addElement(BallerinaCompletionUtils.createPackageLookup(identifier, ColonInsertHandler.INSTANCE_WITH_AUTO_POPUP)); } else if (myElement.getText().equals(identifier.getText())) {
type = fieldTypeName.getText(); myResult.addElement(BallerinaCompletionUtils.createFieldLookupElement(identifier, owner, type, BallerinaPsiImplUtil.getObjectFieldDefaultValue(ballerinaFieldDefinition), null, false, false));
type = fieldTypeName.getText(); myResult.addElement(BallerinaCompletionUtils.createFieldLookupElement (identifier, resolvedElement, type, BallerinaPsiImplUtil.getObjectFieldDefaultValue if (identifier != null) { if (myResult != null) { myResult.addElement(BallerinaCompletionUtils.createVariableLookupElement(identifier, BallerinaPsiImplUtil.formatBallerinaTypeName(ballerinaCatchClause.getTypeName()))); } else if (myElement.getText().equals(identifier.getText())) {
if (identifier != null) { if (myResult != null) { myResult.addElement(BallerinaCompletionUtils .createFunctionLookupElement(definition, SmartParenthesisInsertHandler.INSTANCE));
myResult.addElement(BallerinaCompletionUtils.createFieldLookupElement(definitionIdentifier, ownerName, typeName, null, ColonInsertHandler.INSTANCE_WITH_SPACE, true, false)); } else if (myElement.getText().equals(definitionIdentifier.getText())) {