-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from alephium/Add-muti-project
Add multi project
- Loading branch information
Showing
19 changed files
with
108 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import vscode, { Uri } from 'vscode' | ||
import path from 'path' | ||
import { Root } from './root' | ||
import { Identifier } from './identifier' | ||
import { Word } from './word' | ||
import { Position } from './position' | ||
|
||
export class MultiProjects { | ||
projects: Map<string, Root> | ||
|
||
constructor() { | ||
this.projects = new Map<string, Root>() | ||
} | ||
|
||
projectDir(projectPath: Uri | string): string { | ||
if (projectPath instanceof Uri) { | ||
if (vscode.workspace.rootPath) { | ||
return projectPath.path.split(vscode.workspace.rootPath)[1].split(path.sep)[1] | ||
} | ||
return 'root' | ||
} | ||
return <string>projectPath | ||
} | ||
|
||
merge(path: Uri, members: Identifier[]) { | ||
const dir = this.projectDir(path) | ||
if (this.projects.get(dir)) { | ||
this.root(path)?.merge(path, members) | ||
} else { | ||
const root = new Root() | ||
root.merge(path, members) | ||
this.projects.set(dir, root) | ||
} | ||
} | ||
|
||
remove(path: Uri) { | ||
return this.root(path)?.remove(path) | ||
} | ||
|
||
def(path: Uri | string, word: Word): Identifier | undefined { | ||
return this.root(path)?.def(word) | ||
} | ||
|
||
defs(path?: Uri | string): Identifier[] { | ||
if (path) { | ||
const root = this.root(path) | ||
if (root) return root.defs() | ||
return [] | ||
} | ||
const items: Identifier[] = [] | ||
this.projects.forEach((root) => items.push(...root.defs())) | ||
return items | ||
} | ||
|
||
get(path: Uri | string, name: string): Identifier | undefined { | ||
return this.root(path)?.get(name) | ||
} | ||
|
||
container(path: Uri | string, position: Position): Identifier | undefined { | ||
return this.root(path)?.container(position) | ||
} | ||
|
||
findAll(path: Uri | string, identifier: Word): Identifier[] { | ||
const root = this.root(path) | ||
if (root) return root.findAll(identifier) | ||
return [] | ||
} | ||
|
||
root(path: Uri | string): Root { | ||
const dir = this.projectDir(path) | ||
const root = this.projects.get(dir) | ||
if (root) return root | ||
return new Root() | ||
} | ||
|
||
analyse() { | ||
this.projects.forEach((root) => root.analyse()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { Root } from '../ast/root' | ||
import { MultiProjects } from '../ast/project' | ||
|
||
const cache = new Root() | ||
// const cache = new Root() | ||
const cache = new MultiProjects() | ||
export default cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters