Skip to content

Commit

Permalink
Recursive load path entries. Don't print out rpcs if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuebner committed Jan 9, 2024
1 parent 6347e9b commit f752fa0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
3 changes: 2 additions & 1 deletion yang-lsp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ build/
bin/
xtend-gen/
xtext-gen/
YangFlexer.java*
YangFlexer.java*
/eyang_repository/
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ class DataTreeSerializer {
«FOR child : moduleData.getChildren?:#[]»
«doSerialize(child, '', needsConnect(child, moduleData.getChildren))»
«ENDFOR»
«IF moduleData.getRpcs !== null»
rpcs:
«FOR rpc : moduleData.getRpcs?:#[]»
«FOR rpc : moduleData.getRpcs»
«doSerialize(rpc, '', needsConnect(rpc, moduleData.getRpcs))»
«ENDFOR»
«ENDIF»
'''
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static void main(String[] args) {
}

var output = new StringBuilder();
if(cliArgs.format != null) {
if (cliArgs.format != null) {
yangProcessor.serialize(processedData, cliArgs.format, output);
} else {
processedData.getMessages().forEach(msg -> output.append(msg.toString()).append(System.lineSeparator()));
Expand All @@ -113,34 +113,36 @@ private static List<AbstractModule> loadModuleFileAndDependencies(String moduleF
var moduleResource = rs.createResource(URI.createFileURI(moduleFile.getAbsolutePath()));

// add files from the current directory
var implicitLookup = moduleFile.getAbsoluteFile().getParentFile();
var implicitLookup = new File("").getAbsoluteFile();
var extensionProvider = injector.getInstance(FileExtensionProvider.class);
var fileExts = Collections.singleton("yang");
if (extensionProvider != null && extensionProvider.getFileExtensions() != null) {
if (!extensionProvider.getFileExtensions().isEmpty())
fileExts = extensionProvider.getFileExtensions();
}
loadAdditionalFiles(implicitLookup, rs, fileExts);
loadAdditionalFiles(implicitLookup, rs, fileExts, false);

// handle --path argument
if (paths != null) {
for (String path : paths) {
var folder = new File(path);
if (!folder.isDirectory()) {
System.err.println(folder.getAbsolutePath() + " is not a directory. Skipped.");
} else {
loadAdditionalFiles(folder.getAbsoluteFile(), rs, fileExts);
}
if (!folder.exists()) {
System.err.println("Path " + folder.getAbsolutePath() + " doesn't exist. Skipped.");
} else if (!folder.isDirectory()) {
System.err.println("Path " + folder.getAbsolutePath() + " is not a directory. Skipped.");
}
loadAdditionalFiles(folder.getAbsoluteFile(), rs, fileExts, true);
}
}

// load models
moduleResource.load(rs.getLoadOptions());
EcoreUtil.resolveAll(moduleResource);

// Collect all contained modules
var modules = new ArrayList<AbstractModule>();
for (Resource res : rs.getResources()) {
// Resolve all proxies. Otherwise resolving might fail when copying EObjects
EcoreUtil.resolveAll(res);
var rootObj = res.getContents().get(0);
if (rootObj instanceof AbstractModule) {
modules.add((AbstractModule) rootObj);
Expand All @@ -149,11 +151,17 @@ private static List<AbstractModule> loadModuleFileAndDependencies(String moduleF
return modules;
}

private static void loadAdditionalFiles(File parent, XtextResourceSet rs, Set<String> fileExtensions) {
private static void loadAdditionalFiles(File parent, XtextResourceSet rs, Set<String> fileExtensions,
final boolean recursive) {
for (File file : parent.listFiles()) {
URI fileURI = URI.createFileURI(file.getAbsolutePath());
if (file.isFile() && fileExtensions.contains(fileURI.fileExtension())) {
rs.getResource(fileURI, true);
if(rs.getResource(fileURI, false) == null) {
rs.getResource(fileURI, true);
}
}
if (recursive && file.isDirectory()) { // TODO allow to disable with --no-path-recurse argument
loadAdditionalFiles(file, rs, fileExtensions, recursive);
}
}
}
Expand Down

0 comments on commit f752fa0

Please sign in to comment.