shanedell commented on code in PR #1177: URL: https://github.com/apache/daffodil-vscode/pull/1177#discussion_r1980113163
########## src/rootCompletion/utils.ts: ########## @@ -0,0 +1,106 @@ +/* + * 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. + */ + +import * as fs from 'fs' +import * as vscode from 'vscode' +import { queryXML } from 'xmlUtils' + +// Method to create simple completion item given provided value and position +export function getSimpleCompletionItem( + value: string, + position: vscode.Position +): vscode.CompletionItem { + let item = new vscode.CompletionItem( + `${value}`, + vscode.CompletionItemKind.Value + ) + item.range = new vscode.Range(position, position) + return item +} + +// Method to get previous lines based on i. +function getPrevLines( + document: vscode.TextDocument, + i: number +): vscode.TextLine[] { + let prevLines: vscode.TextLine[] = [] + + for (var j = 0; j < 4; j++) { + if (i > j) { + prevLines.push(document.lineAt(i - (j + 1))) + } + } + + return prevLines +} + +// Method to get the schema path from the configuration file being edited +export function getSchemaPathFromLaunchJSON( Review Comment: @stevedlawrence So, for reading the whole JSON file that causes an issue where you have multiple different configurations, causing the possibility of grabbing the incorrect schema from a different config the users isn't actually trying to use. To do the processing to make sure we grab the correct config might slow down the auto-suggestions and like you mentioned could cause an issue if the json isn't valid. Since if it's not valid we probably won't be able to access any of the data. The reason for only doing 4 lines back is because the `schema` object only has 3 attributes which are `path`, `rootName` and `rootNamespace`. This was to ensure we grab the schema's path since the object `infosetOutput` also has a attribute of `path`. But the reason for 4 was because schema should never be further than 3 back, when you are trying to set the `rootName` or `rootNamespace` as those have to be inside of the schema object. Just added an extra line as a buffer. It's possible that we could just go line by line back from the entered line if it contains `rootName` or `rootNamespace` till we hit `schema`. Then from there grab the next 3 lines after `schema`, as those should be `rootName`, `rootNamespace` and `path`. However, if the key doesn't match one of those 3 we ignore the line and if path isn't found return nothing. Does this sound like a better alternative? -- 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]
