-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Indexing single Lingua Franca projects #181
Changes from 3 commits
726df97
372af0e
f53f2bc
4293ccd
5b03d0b
4d80754
2d617a2
8693054
7d2b1f7
3f0a776
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,7 +127,7 @@ export class LFDataProviderNode extends vscode.TreeItem { | |
newIcon, | ||
sameRootAsEditor | ||
? new vscode.ThemeColor('editorIcon.currentProject') | ||
: new vscode.ThemeColor('editorIcon.notCurrentProject') | ||
: undefined | ||
); | ||
} | ||
|
||
|
@@ -183,7 +183,7 @@ export class LFDataProviderNode extends vscode.TreeItem { | |
return editor.document.uri.fsPath.startsWith(this.uri.fsPath); | ||
} | ||
const pathSegments = this.uri.fsPath.split('/'); | ||
const srcOrBuildIndex = pathSegments.indexOf(this.type === LFDataProviderNodeType.LIBRARY ? 'build' : 'src'); | ||
const srcOrBuildIndex = pathSegments.lastIndexOf(this.type === LFDataProviderNodeType.LIBRARY ? 'build' : 'src'); | ||
|
||
if (srcOrBuildIndex === -1) { | ||
return false; | ||
|
@@ -219,11 +219,11 @@ export class LFDataProvider implements vscode.TreeDataProvider<LFDataProviderNod | |
private data: LFDataProviderNode[] = []; | ||
|
||
// Utility properties | ||
private searchSourceFiles: string = '**/src/*.lf'; | ||
private searchPathLocal: string = '**/src/lib/*.lf'; | ||
private searchPathLibrary: vscode.GlobPattern = '**/build/lfc_include/**/src/lib/*.lf'; | ||
private searchSourceFiles: vscode.GlobPattern = 'src/**/*.lf'; | ||
private searchPathLocal: vscode.GlobPattern = 'src/lib/*.lf'; | ||
private searchPathLibrary: vscode.GlobPattern = 'build/lfc_include/**/src/lib/*.lf'; | ||
private exclude_path_local: vscode.GlobPattern = '**/build/**'; // only for local LF libraries | ||
private exclude_path_src: vscode.GlobPattern = `{${this.exclude_path_local},**/fed-gen/**,**/src-gen/***}` | ||
private exclude_path_src: vscode.GlobPattern = `{${this.exclude_path_local},${this.searchPathLocal},**/fed-gen/**,**/src-gen/***}` | ||
|
||
// Event emitter for tree data change | ||
private _onDidChangeTreeData: vscode.EventEmitter<LFDataProviderNode | undefined | null | void> = new vscode.EventEmitter<LFDataProviderNode | undefined | null | void>(); | ||
|
@@ -245,7 +245,6 @@ export class LFDataProvider implements vscode.TreeDataProvider<LFDataProviderNod | |
private client: LanguageClient, | ||
private context: vscode.ExtensionContext, | ||
) { | ||
|
||
// Register to file system changes: Create, Delete, Rename, Change | ||
this.watchFileChanges(this.context); | ||
|
||
|
@@ -361,7 +360,6 @@ export class LFDataProvider implements vscode.TreeDataProvider<LFDataProviderNod | |
updateIfExists(LFDataProviderNodeType.SOURCE); | ||
} | ||
}); | ||
|
||
this._onDidChangeTreeData.fire(undefined); | ||
} | ||
|
||
|
@@ -401,7 +399,6 @@ export class LFDataProvider implements vscode.TreeDataProvider<LFDataProviderNod | |
} | ||
this._onDidChangeTreeData.fire(undefined); | ||
} | ||
|
||
findFiles(searchPath: string | vscode.GlobPattern, exclude_path: vscode.GlobPattern | null, type: LFDataProviderNodeType): void { | ||
vscode.workspace.findFiles(searchPath, exclude_path ? exclude_path : null).then(uris => { | ||
uris.forEach(uri => { | ||
|
@@ -577,7 +574,7 @@ export class LFDataProvider implements vscode.TreeDataProvider<LFDataProviderNod | |
*/ | ||
buildRoot(uri: string, type: LFDataProviderNodeType | null): LFDataProviderNode { | ||
const splittedUri = uri.split('/'); | ||
const srcIdx = splittedUri.indexOf(!type || type == LFDataProviderNodeType.LIBRARY ? 'build' : 'src'); | ||
const srcIdx = splittedUri.lastIndexOf(!type || type == LFDataProviderNodeType.LIBRARY ? 'build' : 'src'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change? This seems to relate to our discussion. The question is whether we should find the file relative to the root of the workspace, or fine the root of the package by traversing up from the file. In There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use the last index because the ├── project
...
│ ├── src/ # Contains LF source files
│ │ ├── SourceFile.lf # Can also be in a subfolder, e.g. source1/SourceFile.lf
│ │ ├── lib/ # Directory for storing reusable reactors
│ │ │ ├── Input.lf # Example: reactor capturing external inputs (e.g., Microphone, Camera)
│ ├── build/ # Directory containing lingo packages
│ │ ├── lfc_include/ # Directory for storing reusable reactors
│ │ │ ├── lingo_downloaded_library/
... Let's assume the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sense depending on whether we want to let the open file dictate the behavior of the editor or whether we want the workspace to do that. Here, you're switching from the latter to the former. We have to make sure this is what we want. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It also leaves unanswered the question of what to do when no file is opened in the editor. Do we look down in case no file is opened and up in case there is an open file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the answer to this is here as well |
||
const projectLabel = splittedUri[srcIdx - 1]; | ||
|
||
const existingProject = this.data.find(item => item.label === projectLabel); | ||
|
@@ -598,7 +595,7 @@ export class LFDataProvider implements vscode.TreeDataProvider<LFDataProviderNod | |
*/ | ||
buildLibraryRoot(uri: string, root: LFDataProviderNode, dataNode: LFDataProviderNode): LFDataProviderNode { | ||
const splittedUri = uri.split('/'); | ||
const srcIdx = splittedUri.indexOf('src'); | ||
const srcIdx = splittedUri.lastIndexOf('src'); | ||
const projectLabel = splittedUri[srcIdx - 1]; | ||
|
||
let lingo = this.findOrCreateSubNode(root, "Lingo Packages", LFDataProviderNodeRole.SUB, LFDataProviderNodeType.LIBRARY, dataNode); | ||
|
@@ -703,7 +700,7 @@ export class LFDataProvider implements vscode.TreeDataProvider<LFDataProviderNod | |
*/ | ||
getLibraryPath(path: string) { | ||
const segments = path.split('/'); | ||
const srcIndex = segments.indexOf('src'); | ||
const srcIndex = segments.lastIndexOf('src'); | ||
|
||
// Check if the 'src' directory was found and there's at least one segment before it | ||
if (srcIndex === -1 || srcIndex === 0) { | ||
|
@@ -764,7 +761,7 @@ export class LFDataProvider implements vscode.TreeDataProvider<LFDataProviderNod | |
*/ | ||
goToLingoTomlCommand(node: LFDataProviderNode) { | ||
const segments = node.uri.fsPath.split('/'); | ||
const srcIdx = segments.indexOf('build'); | ||
const srcIdx = segments.lastIndexOf('build'); | ||
let newUri = segments.slice(0, srcIdx).join('/').concat('/Lingo.toml'); | ||
vscode.workspace.openTextDocument(vscode.Uri.parse(newUri)).then(doc => { | ||
vscode.window.showTextDocument(doc); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we point to a specific page?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that’s the idea. Do you know which specific page?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://www.lf-lang.org/docs/tools/code-extension/#usage but this page it rather incomplete. Also, there is no functionality to create a new project, or a description of how to do so. Should be easy to let
lingo
do it via VS Code once it's available as a library...