entlicher commented on a change in pull request #3025: URL: https://github.com/apache/netbeans/pull/3025#discussion_r662615574
########## File path: java/java.lsp.server/vscode/src/launchConfigurations.ts ########## @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +'use strict'; + +import { commands, CompletionItem, CompletionList, ExtensionContext, languages, ProviderResult, SnippetString } from 'vscode'; +import { InsertTextFormat } from 'vscode-languageclient'; +import * as jsoncp from 'jsonc-parser'; + +export function registerCompletion(context: ExtensionContext) { + context.subscriptions.push(languages.registerCompletionItemProvider({ language: 'jsonc', pattern: '**/launch.json' }, { + provideCompletionItems(document, position, cancelToken) { + const sourceText = document.getText(); + const root = jsoncp.parseTree(sourceText); + if (root) { + const offset = document.offsetAt(position); + const currentNode = jsoncp.findNodeAtOffset(root, offset); + if (currentNode) { + const path = jsoncp.getNodePath(currentNode); + if (path.length >= 1 && 'configurations' == path[0]) { + const uri = document.uri.toString(); + let completionItems: ProviderResult<CompletionList<CompletionItem>> | CompletionItem[]; + if (path.length == 1) { + // Get all configurations: + completionItems = commands.executeCommand('java.project.configuration.completion', uri); + } else { + let node: jsoncp.Node = currentNode; + if (currentNode.type == 'property' && currentNode.parent) { + let propName = currentNode.children?.[0]?.value; + node = currentNode.parent; + let attributesMap = getAttributes(node); + // Get possible values of property 'propName': + completionItems = commands.executeCommand('java.project.configuration.completion', uri, attributesMap, propName); Review comment: I don't think it can be undefined. A property ought to have a name. If this can ever happen, I'd not call anything and return simply and empty CompletionList. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
