mirror of
https://github.com/fluencelabs/aqua-vscode
synced 2025-03-15 13:50:52 +00:00
feat: add useOnlyImportsFromSettings
flag (#41)
This commit is contained in:
parent
4d26bfe686
commit
6b73358330
18
package.json
18
package.json
@ -62,11 +62,19 @@
|
||||
"type": "object",
|
||||
"title": "Aqua",
|
||||
"properties": {
|
||||
"aquaSettings.imports": {
|
||||
"scope": "resource",
|
||||
"type": "array",
|
||||
"default": [],
|
||||
"description": "Adds imports for aqua file or project"
|
||||
"aquaSettings": {
|
||||
"imports": {
|
||||
"scope": "resource",
|
||||
"type": "array",
|
||||
"default": [],
|
||||
"description": "Adds imports for aqua file or project"
|
||||
},
|
||||
"enableLegacyAutoImportSearch": {
|
||||
"scope": "resource",
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Do not look for extra imports"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
14
server/package-lock.json
generated
14
server/package-lock.json
generated
@ -8,7 +8,7 @@
|
||||
"name": "aqua-ls-server",
|
||||
"version": "0.0.1",
|
||||
"dependencies": {
|
||||
"@fluencelabs/aqua-language-server-api": "0.11.0",
|
||||
"@fluencelabs/aqua-language-server-api": "0.11.7",
|
||||
"global-dirs": "^3.0.0",
|
||||
"vscode-languageserver": "^7.0.0",
|
||||
"vscode-languageserver-textdocument": "^1.0.4"
|
||||
@ -30,9 +30,9 @@
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/@fluencelabs/aqua-language-server-api": {
|
||||
"version": "0.11.0",
|
||||
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua-language-server-api/-/aqua-language-server-api-0.11.0.tgz",
|
||||
"integrity": "sha512-DVgbh3rmgA6COfNXCnkjRcvw3uNLtnuZhs2wM+m2RfShE9OI6gJzqPij6DgQIP/RQEFGql47EcpQ95t0WoMvRQ=="
|
||||
"version": "0.11.7",
|
||||
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua-language-server-api/-/aqua-language-server-api-0.11.7.tgz",
|
||||
"integrity": "sha512-Ik+DWWVOe2tsZ7IwHvCpKVggkpbNp66yKc6LRc3m1xV3Rpjoe+u4HJAab4Uj3TbZNn33lOY+DUj0J+QbPj5EMA=="
|
||||
},
|
||||
"node_modules/global-dirs": {
|
||||
"version": "3.0.0",
|
||||
@ -97,9 +97,9 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@fluencelabs/aqua-language-server-api": {
|
||||
"version": "0.11.0",
|
||||
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua-language-server-api/-/aqua-language-server-api-0.11.0.tgz",
|
||||
"integrity": "sha512-DVgbh3rmgA6COfNXCnkjRcvw3uNLtnuZhs2wM+m2RfShE9OI6gJzqPij6DgQIP/RQEFGql47EcpQ95t0WoMvRQ=="
|
||||
"version": "0.11.7",
|
||||
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua-language-server-api/-/aqua-language-server-api-0.11.7.tgz",
|
||||
"integrity": "sha512-Ik+DWWVOe2tsZ7IwHvCpKVggkpbNp66yKc6LRc3m1xV3Rpjoe+u4HJAab4Uj3TbZNn33lOY+DUj0J+QbPj5EMA=="
|
||||
},
|
||||
"global-dirs": {
|
||||
"version": "3.0.0",
|
||||
|
@ -11,7 +11,7 @@
|
||||
"url": "https://github.com/fluencelabs/aqua"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fluencelabs/aqua-language-server-api": "0.11.0",
|
||||
"@fluencelabs/aqua-language-server-api": "0.11.7",
|
||||
"global-dirs": "^3.0.0",
|
||||
"vscode-languageserver": "^7.0.0",
|
||||
"vscode-languageserver-textdocument": "^1.0.4"
|
||||
|
@ -27,6 +27,7 @@ let folders: WorkspaceFolder[] = [];
|
||||
|
||||
export interface Settings {
|
||||
imports: string[];
|
||||
enableLegacyAutoImportSearch: boolean;
|
||||
}
|
||||
|
||||
function searchDefinition(position: Position, name: string, locations: TokenLink[]): TokenLink | undefined {
|
||||
@ -44,7 +45,7 @@ function searchDefinition(position: Position, name: string, locations: TokenLink
|
||||
// The global settings, used when the `workspace/configuration` request is not supported by the client.
|
||||
// Please note that this is not the case when using this server with the client provided in this example
|
||||
// but could happen with other clients.
|
||||
const defaultSettings: Settings = { imports: [] };
|
||||
const defaultSettings: Settings = { imports: [], enableLegacyAutoImportSearch: false };
|
||||
let globalSettings: Settings = defaultSettings;
|
||||
|
||||
// Cache the settings of all open documents
|
||||
|
@ -40,20 +40,21 @@ function notEmpty<TValue>(value: TValue | null | undefined): value is TValue {
|
||||
return value !== null && value !== undefined;
|
||||
}
|
||||
|
||||
export async function compileAqua(
|
||||
function getImports(
|
||||
settings: Settings,
|
||||
textDocument: TextDocument,
|
||||
folders: WorkspaceFolder[],
|
||||
console: RemoteConsole,
|
||||
): Promise<[Diagnostic[], TokenLink[]]> {
|
||||
const uri = textDocument.uri.replace('file://', '');
|
||||
|
||||
) {
|
||||
let imports: string[] = [];
|
||||
|
||||
const assumeImports = settings.enableLegacyAutoImportSearch;
|
||||
|
||||
const openFolders = folders.map((f) => f.uri.replace('file://', ''));
|
||||
|
||||
// add all workspace folders to imports
|
||||
// 1. open folders
|
||||
imports = imports.concat(openFolders);
|
||||
if (assumeImports) imports = imports.concat(openFolders);
|
||||
|
||||
// 2. imports from settings
|
||||
if (settings.imports && Array.isArray(settings.imports)) {
|
||||
@ -79,22 +80,40 @@ export async function compileAqua(
|
||||
.flat();
|
||||
|
||||
imports = imports.concat(relativeImports);
|
||||
imports = imports.concat(relativeImports.map((s) => Path.join(s, '/node_modules')));
|
||||
imports = imports.concat(absoluteImports);
|
||||
imports = imports.concat(absoluteImports.map((s) => Path.join(s, '/node_modules')));
|
||||
|
||||
if (assumeImports) {
|
||||
imports = imports.concat(relativeImports.map((s) => Path.join(s, '/node_modules')));
|
||||
imports = imports.concat(absoluteImports.map((s) => Path.join(s, '/node_modules')));
|
||||
}
|
||||
}
|
||||
|
||||
// 3. node_modules in open folders
|
||||
imports = imports.concat(openFolders.map((f) => Path.join(f, '/node_modules')));
|
||||
if (assumeImports) {
|
||||
// 3. node_modules in open folders
|
||||
imports = imports.concat(openFolders.map((f) => Path.join(f, '/node_modules')));
|
||||
|
||||
// 4. path to aqua library
|
||||
if (require.main) {
|
||||
imports = imports.concat(require.main.paths);
|
||||
// 4. path to aqua library
|
||||
if (require.main) {
|
||||
imports = imports.concat(require.main.paths);
|
||||
}
|
||||
|
||||
// 5. node_modules from root to open folders
|
||||
const nodeModulesPaths = folders.map((f) => findNearestNodeModules(textDocument.uri, f.uri)).filter(notEmpty);
|
||||
imports = imports.concat(nodeModulesPaths);
|
||||
}
|
||||
|
||||
// 5. node_modules from root to open folders
|
||||
const nodeModulesPaths = folders.map((f) => findNearestNodeModules(textDocument.uri, f.uri)).filter(notEmpty);
|
||||
imports = imports.concat(nodeModulesPaths);
|
||||
return imports;
|
||||
}
|
||||
|
||||
export async function compileAqua(
|
||||
settings: Settings,
|
||||
textDocument: TextDocument,
|
||||
folders: WorkspaceFolder[],
|
||||
console: RemoteConsole,
|
||||
): Promise<[Diagnostic[], TokenLink[]]> {
|
||||
const uri = textDocument.uri.replace('file://', '');
|
||||
|
||||
const imports = getImports(settings, textDocument, folders, console);
|
||||
|
||||
// compile aqua and get possible errors
|
||||
const result = await AquaLSP.compile(uri, imports);
|
||||
|
Loading…
x
Reference in New Issue
Block a user