Skip to content

Commit

Permalink
refactor(configuration): avoid unnecessary configuration event
Browse files Browse the repository at this point in the history
Not send event when not find folder configuration file, avoid issues
when opening library files out of workspace folder.

Closes #3625
  • Loading branch information
chemzqm committed Feb 7, 2022
1 parent 94dd227 commit 2c4ba90
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 2 additions & 7 deletions src/configuration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,16 @@ export default class Configurations {
let u = URI.parse(uri)
if (u.scheme != 'file') return
let filepath = u.fsPath
let find = false
for (let [configFile, model] of this.foldConfigurations) {
let root = path.resolve(configFile, '../..')
if (isParentFolder(root, filepath, true)) {
find = true
if (this.workspaceConfigFile != configFile) {
logger.debug('Change folder configuration to:', configFile)
this.changeConfiguration(ConfigurationTarget.Workspace, model, configFile)
}
break
}
}
if (this.workspaceConfigFile && find === false) {
logger.debug('reset folder configuration to empty')
this.changeConfiguration(ConfigurationTarget.Workspace, { contents: {} }, undefined)
}
}

public hasFolderConfiguration(filepath: string): boolean {
Expand Down Expand Up @@ -325,7 +320,7 @@ export default class Configurations {
let folder = findUp('.vim', rootPath)
if (folder) {
let file = path.join(folder, CONFIG_FILE_NAME)
if (fs.existsSync(file)) {
if (!sameFile(file, this.userConfigFile) && fs.existsSync(file)) {
this.addFolderFile(file)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export function readFileLine(fullpath: string, count: number): Promise<string> {
})
}

export function sameFile(fullpath: string, other: string): boolean {
export function sameFile(fullpath: string | null, other: string | null): boolean {
const caseInsensitive = platform.isWindows || platform.isMacintosh
if (!fullpath || !other) return false
if (caseInsensitive) return fullpath.toLowerCase() === other.toLowerCase()
Expand Down

0 comments on commit 2c4ba90

Please sign in to comment.