-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configurable folder excludes #344
- Loading branch information
Showing
14 changed files
with
267 additions
and
63 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
53 changes: 53 additions & 0 deletions
53
packages/langium-vscode/src/language-server/grammar-workspace-manager.ts
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,53 @@ | ||
/****************************************************************************** | ||
* Copyright 2022 TypeFox GmbH | ||
* This program and the accompanying materials are made available under the | ||
* terms of the MIT License, which is available in the project root. | ||
******************************************************************************/ | ||
|
||
import ignore, { Ignore } from 'ignore'; | ||
import { LangiumGrammarLanguageMetaData } from 'langium/src/grammar/generated/module'; | ||
import { LangiumSharedServices } from 'langium/src/services'; | ||
import { ConfigurationProvider } from 'langium/src/workspace/configuration'; | ||
import { FileSystemNode } from 'langium/src/workspace/file-system-provider'; | ||
import { DefaultWorkspaceManager } from 'langium/src/workspace/workspace-manager'; | ||
import * as path from 'path'; | ||
import { CancellationToken, WorkspaceFolder } from 'vscode-languageserver-protocol'; | ||
import { URI, Utils } from 'vscode-uri'; | ||
|
||
const CONFIG_KEY = 'build'; | ||
|
||
interface WorkspaceManagerConf { | ||
/** | ||
* gitignore-style exclusion patterns, separated by comma | ||
*/ | ||
ignorePatterns: string | ||
} | ||
|
||
export class LangiumGrammarWorkspaceManager extends DefaultWorkspaceManager { | ||
|
||
protected readonly configurationProvider: ConfigurationProvider; | ||
protected matcher: Ignore | undefined; | ||
|
||
constructor(services: LangiumSharedServices) { | ||
super(services); | ||
this.configurationProvider = services.workspace.ConfigurationProvider; | ||
} | ||
|
||
async initializeWorkspace(folders: WorkspaceFolder[], cancelToken = CancellationToken.None): Promise<void> { | ||
const buildConf: WorkspaceManagerConf = await this.configurationProvider.getConfiguration(LangiumGrammarLanguageMetaData.languageId, CONFIG_KEY); | ||
const ignorePatterns = buildConf.ignorePatterns?.split(',')?.map(pattern => pattern.trim())?.filter(pattern => pattern.length > 0); | ||
this.matcher = ignorePatterns ? ignore().add(ignorePatterns) : undefined; | ||
return super.initializeWorkspace(folders, cancelToken); | ||
} | ||
|
||
protected includeEntry(workspaceFolder: WorkspaceFolder, entry: FileSystemNode, fileExtensions: string[]): boolean { | ||
if (this.matcher) { | ||
// create path relative to workspace folder root: /user/foo/workspace/entry.txt -> entry.txt | ||
const relPath = path.relative(URI.parse(workspaceFolder.uri).path, entry.uri.path); | ||
const ignored = this.matcher.ignores(relPath); | ||
return !ignored && (entry.isDirectory || (entry.isFile && fileExtensions.includes(Utils.extname(entry.uri)))); | ||
} | ||
return super.includeEntry(workspaceFolder, entry, fileExtensions); | ||
} | ||
|
||
} |
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
Oops, something went wrong.