mirror of
https://github.com/fluencelabs/aqua-vscode
synced 2025-03-15 13:50:52 +00:00
delete legacy import, pass new improts to compiler (#74)
This commit is contained in:
parent
3fad69ba77
commit
ba3192f988
@ -107,12 +107,6 @@
|
||||
"default": {},
|
||||
"description": "Adds imports for aqua file or project"
|
||||
},
|
||||
"aquaSettings.enableLegacyAutoImportSearch": {
|
||||
"scope": "resource",
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Do not look for extra imports"
|
||||
},
|
||||
"aquaSettings.fluencePath": {
|
||||
"scope": "resource",
|
||||
"type": [
|
||||
|
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.13.2",
|
||||
"@fluencelabs/aqua-language-server-api": "0.13.3",
|
||||
"global-dirs": "^3.0.0",
|
||||
"vscode-languageserver": "^7.0.0",
|
||||
"vscode-languageserver-textdocument": "^1.0.4",
|
||||
@ -31,9 +31,9 @@
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/@fluencelabs/aqua-language-server-api": {
|
||||
"version": "0.13.2",
|
||||
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua-language-server-api/-/aqua-language-server-api-0.13.2.tgz",
|
||||
"integrity": "sha512-hvq4/pB4kPx9t8z9NwM0BYxcXDtyN6h+SS4dmmZ/wSSLIEVWglKDc8R/JXAky96sPwdr1zNrNpNTnH0Ta9xJpw=="
|
||||
"version": "0.13.3",
|
||||
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua-language-server-api/-/aqua-language-server-api-0.13.3.tgz",
|
||||
"integrity": "sha512-5R16UZsdtGPrqdC7E7sZAMnMVWt5AQgeI895KF+jtx6SdBksnG6NGa7alRWNQlaKe5HmB2xBUaVzOCckmwvhfg=="
|
||||
},
|
||||
"node_modules/global-dirs": {
|
||||
"version": "3.0.0",
|
||||
@ -103,9 +103,9 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@fluencelabs/aqua-language-server-api": {
|
||||
"version": "0.13.2",
|
||||
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua-language-server-api/-/aqua-language-server-api-0.13.2.tgz",
|
||||
"integrity": "sha512-hvq4/pB4kPx9t8z9NwM0BYxcXDtyN6h+SS4dmmZ/wSSLIEVWglKDc8R/JXAky96sPwdr1zNrNpNTnH0Ta9xJpw=="
|
||||
"version": "0.13.3",
|
||||
"resolved": "https://registry.npmjs.org/@fluencelabs/aqua-language-server-api/-/aqua-language-server-api-0.13.3.tgz",
|
||||
"integrity": "sha512-5R16UZsdtGPrqdC7E7sZAMnMVWt5AQgeI895KF+jtx6SdBksnG6NGa7alRWNQlaKe5HmB2xBUaVzOCckmwvhfg=="
|
||||
},
|
||||
"global-dirs": {
|
||||
"version": "3.0.0",
|
||||
|
@ -11,7 +11,7 @@
|
||||
"url": "https://github.com/fluencelabs/aqua"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fluencelabs/aqua-language-server-api": "0.13.2",
|
||||
"@fluencelabs/aqua-language-server-api": "0.13.3",
|
||||
"global-dirs": "^3.0.0",
|
||||
"vscode-languageserver": "^7.0.0",
|
||||
"vscode-languageserver-textdocument": "^1.0.4",
|
||||
|
@ -184,7 +184,7 @@ async function validateDocument(textDocument: TextDocument): Promise<void> {
|
||||
|
||||
connection.console.log(`validateDocument ${textDocument.uri} with settings ${JSON.stringify(settings)}`);
|
||||
|
||||
const [diagnostics, locations, tokenInfos] = await compileAqua(settings, textDocument, folders, connection.console);
|
||||
const [diagnostics, locations, tokenInfos] = await compileAqua(settings, textDocument);
|
||||
|
||||
allPageInfo.set(textDocument.uri, { links: locations, tokens: tokenInfos });
|
||||
|
||||
|
@ -7,7 +7,6 @@ import type { FluenceCli } from './cli';
|
||||
|
||||
export interface Settings {
|
||||
imports: Imports;
|
||||
enableLegacyAutoImportSearch: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,7 +62,6 @@ export interface SettingsManagerConfig {
|
||||
export class SettingsManager {
|
||||
private readonly defaultSettings: Settings = {
|
||||
imports: {},
|
||||
enableLegacyAutoImportSearch: false,
|
||||
};
|
||||
private documents: Map<string, DocumentInfo> = new Map();
|
||||
|
||||
|
@ -2,8 +2,7 @@ import * as fs from 'fs';
|
||||
import * as Path from 'path';
|
||||
|
||||
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
||||
import { Diagnostic, DiagnosticSeverity, RemoteConsole } from 'vscode-languageserver/node';
|
||||
import type { WorkspaceFolder } from 'vscode-languageserver-protocol';
|
||||
import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver/node';
|
||||
|
||||
import {
|
||||
AquaLSP,
|
||||
@ -15,104 +14,6 @@ import {
|
||||
|
||||
import type { Settings } from './settings';
|
||||
|
||||
function findNearestNodeModules(fileLocation: string, projectLocation: string): string | undefined {
|
||||
const relative = Path.relative(projectLocation, fileLocation);
|
||||
|
||||
const projectPath = Path.resolve(projectLocation.replace('file://', ''));
|
||||
|
||||
// project location is a part of file location
|
||||
if (relative && !relative.startsWith('..') && !Path.isAbsolute(relative)) {
|
||||
let currentPath = Path.join(fileLocation.replace('file:/', ''), '..');
|
||||
|
||||
let result: string | undefined = undefined;
|
||||
|
||||
while (true) {
|
||||
const possibleNodeModulesPath = Path.join(currentPath, '/node_modules');
|
||||
if (fs.existsSync(possibleNodeModulesPath)) {
|
||||
result = Path.resolve(possibleNodeModulesPath);
|
||||
break;
|
||||
}
|
||||
if (Path.resolve(currentPath) === projectPath) {
|
||||
break;
|
||||
} else {
|
||||
currentPath = Path.join(currentPath, '..');
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function notEmpty<TValue>(value: TValue | null | undefined): value is TValue {
|
||||
return value !== null && value !== undefined;
|
||||
}
|
||||
|
||||
function getImports(
|
||||
settings: Settings,
|
||||
textDocument: TextDocument,
|
||||
folders: WorkspaceFolder[],
|
||||
console: RemoteConsole,
|
||||
) {
|
||||
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
|
||||
if (assumeImports) imports = imports.concat(openFolders);
|
||||
|
||||
// 2. imports from settings
|
||||
if (settings.imports && Array.isArray(settings.imports)) {
|
||||
const validatedImports: string[] = settings.imports.filter((s) => {
|
||||
const isString = typeof s == 'string';
|
||||
if (!isString) {
|
||||
console.warn(
|
||||
`Field 'import' in extension settings must have only array of strings.
|
||||
Cannot add import ${JSON.stringify(s)}`,
|
||||
);
|
||||
}
|
||||
|
||||
return isString;
|
||||
});
|
||||
|
||||
const absoluteImports = validatedImports.filter((s) => Path.isAbsolute(s));
|
||||
|
||||
// relative imports must be started from open folders
|
||||
const relativeImports = validatedImports
|
||||
.filter((s) => !absoluteImports.includes(s))
|
||||
.map((s) => openFolders.map((f) => Path.join(f, s)))
|
||||
.flat();
|
||||
|
||||
imports = imports.concat(relativeImports);
|
||||
imports = imports.concat(absoluteImports);
|
||||
|
||||
if (assumeImports) {
|
||||
imports = imports.concat(relativeImports.map((s) => Path.join(s, '/node_modules')));
|
||||
imports = imports.concat(absoluteImports.map((s) => Path.join(s, '/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);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
function infoToDiagnostic(textDocument: TextDocument, info: ErrorInfo | WarningInfo): Diagnostic {
|
||||
const severity = info.infoType === 'error' ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning;
|
||||
|
||||
@ -145,22 +46,20 @@ function infoToDiagnostic(textDocument: TextDocument, info: ErrorInfo | WarningI
|
||||
export async function compileAqua(
|
||||
settings: Settings,
|
||||
textDocument: TextDocument,
|
||||
folders: WorkspaceFolder[],
|
||||
console: RemoteConsole,
|
||||
): Promise<[Diagnostic[], TokenLink[], TokenInfo[]]> {
|
||||
const uri = textDocument.uri.replace('file://', '');
|
||||
|
||||
const imports = getImports(settings, textDocument, folders, console);
|
||||
|
||||
// compile aqua and get result
|
||||
const result = await AquaLSP.compile(uri, imports);
|
||||
const result = await AquaLSP.compile(uri, settings.imports);
|
||||
|
||||
const diagnostics: Diagnostic[] = [];
|
||||
const links: TokenLink[] = [];
|
||||
|
||||
const docPath = Path.parse(textDocument.uri);
|
||||
const linksSearch = [docPath.dir.replace('file://', '')].concat(imports);
|
||||
|
||||
let linksSearch = [docPath.dir.replace('file://', '')];
|
||||
|
||||
// TODO: fix import locations search
|
||||
result.importLocations.map(function (ti) {
|
||||
const path = linksSearch.map((i) => Path.join(i, ti.path)).find(fs.existsSync);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user