Skip to content

Commit

Permalink
fix(): settings type simplified to one level
Browse files Browse the repository at this point in the history
fix(): folder reference now '/' from '/*'
  • Loading branch information
SStranks committed Nov 1, 2023
1 parent 5915e94 commit 896f755
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/cssLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function createFacade(parser: Parser, completion: CSSCompletion, hover: CSSHover
validation.configure(settings);
completion.configure(settings?.completion);
hover.configure(settings?.hover);
navigation.configure(settings?.alias);
navigation.configure(settings?.importAliases);
},
setDataProviders: cssDataManager.setDataProviders.bind(cssDataManager),
doValidation: validation.doValidation.bind(validation),
Expand Down
4 changes: 2 additions & 2 deletions src/cssLanguageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ export interface LanguageSettings {
lint?: LintSettings;
completion?: CompletionSettings;
hover?: HoverSettings;
alias?: AliasSettings;
importAliases?: AliasSettings;
}

export interface AliasSettings {
paths?: { [key: string]: string };
[key: string]: string;
}

export interface HoverSettings {
Expand Down
12 changes: 6 additions & 6 deletions src/services/cssNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,16 +412,16 @@ export class CSSNavigation {
// Try resolving the reference from the language configuration alias settings
if (ref && !(await this.fileExists(ref))) {
const rootFolderUri = documentContext.resolveReference('/', documentUri);
if (settings?.paths && rootFolderUri) {
if (settings && rootFolderUri) {
// Specific file reference
if (target in settings.paths) {
return this.mapReference(joinPath(rootFolderUri, settings.paths[target]), isRawLink);
if (target in settings) {
return this.mapReference(joinPath(rootFolderUri, settings[target]), isRawLink);
}
// Reference folder
const firstSlash = target.indexOf('/');
const prefix = `${target.substring(0, firstSlash)}/*`;
if (prefix in settings.paths) {
const aliasPath = (settings.paths[prefix]).slice(0, -1);
const prefix = `${target.substring(0, firstSlash)}/`;
if (prefix in settings) {
const aliasPath = (settings[prefix]).slice(0, -1);
let newPath = joinPath(rootFolderUri, aliasPath);
return this.mapReference(newPath = joinPath(newPath, target.substring(prefix.length - 1)), isRawLink);
}
Expand Down
6 changes: 2 additions & 4 deletions src/test/css/navigation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,9 @@ function getCSSLS() {

function aliasSettings(): LanguageSettings {
return {
"alias": {
"paths": {
"importAliases": {
"@SingleStylesheet": "/src/assets/styles.css",
"@AssetsDir/*": "/src/assets/*",
}
"@AssetsDir/": "/src/assets/",
}
};
}
Expand Down
10 changes: 4 additions & 6 deletions src/test/scss/scssNavigation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ function getSCSSLS() {

function aliasSettings(): LanguageSettings {
return {
"alias": {
"paths": {
"importAliases": {
"@SassStylesheet": "/src/assets/styles.scss",
"@NoUnderscoreDir/*": "/noUnderscore/*",
"@UnderscoreDir/*": "/underscore/*",
"@BothDir/*": "/both/*",
"@NoUnderscoreDir/": "/noUnderscore/",
"@UnderscoreDir/": "/underscore/",
"@BothDir/": "/both/",
}
}
};
}

Expand Down

0 comments on commit 896f755

Please sign in to comment.