未验证 提交 82863aac 编写于 作者: M Matt Bierner 提交者: GitHub

Strict null checking snippetsService.ts (#63456)

上级 2f3fc3f6
......@@ -618,6 +618,7 @@
"./vs/workbench/parts/snippets/electron-browser/snippetCompletionProvider.ts",
"./vs/workbench/parts/snippets/electron-browser/snippets.contribution.ts",
"./vs/workbench/parts/snippets/electron-browser/snippetsFile.ts",
"./vs/workbench/parts/snippets/electron-browser/snippetsService.ts",
"./vs/workbench/parts/surveys/electron-browser/nps.contribution.ts",
"./vs/workbench/parts/tasks/common/problemCollectors.ts",
"./vs/workbench/parts/tasks/common/problemMatcher.ts",
......
......@@ -148,8 +148,8 @@ export class SnippetFile {
constructor(
readonly source: SnippetSource,
readonly location: URI,
readonly defaultScopes: string[],
private readonly _extension: IExtensionDescription,
public defaultScopes: string[] | undefined,
private readonly _extension: IExtensionDescription | undefined,
private readonly _fileService: IFileService
) {
this.isGlobalSnippets = extname(location.path) === '.code-snippets';
......
......@@ -39,7 +39,7 @@ namespace snippetExt {
location: URI;
}
export function toValidSnippet(extension: IExtensionPointUser<ISnippetsExtensionPoint[]>, snippet: ISnippetsExtensionPoint, modeService: IModeService): IValidSnippetsExtensionPoint {
export function toValidSnippet(extension: IExtensionPointUser<ISnippetsExtensionPoint[]>, snippet: ISnippetsExtensionPoint, modeService: IModeService): IValidSnippetsExtensionPoint | null {
if (isFalsyOrWhitespace(snippet.path)) {
extension.collector.error(localize(
......@@ -167,28 +167,35 @@ class SnippetsService implements ISnippetsService {
getSnippets(languageId: LanguageId): Promise<Snippet[]> {
return this._joinSnippets().then(() => {
const langName = this._modeService.getLanguageIdentifier(languageId).language;
const result: Snippet[] = [];
const promises: Promise<any>[] = [];
this._files.forEach(file => {
promises.push(file.load()
.then(file => file.select(langName, result))
.catch(err => this._logService.error(err, file.location.toString()))
);
});
const languageIdentifier = this._modeService.getLanguageIdentifier(languageId);
if (languageIdentifier) {
const langName = languageIdentifier.language;
this._files.forEach(file => {
promises.push(file.load()
.then(file => file.select(langName, result))
.catch(err => this._logService.error(err, file.location.toString()))
);
});
}
return Promise.all(promises).then(() => result);
});
}
getSnippetsSync(languageId: LanguageId): Snippet[] {
const langName = this._modeService.getLanguageIdentifier(languageId).language;
const result: Snippet[] = [];
this._files.forEach(file => {
// kick off loading (which is a noop in case it's already loaded)
// and optimistically collect snippets
file.load().catch(err => { /*ignore*/ });
file.select(langName, result);
});
const languageIdentifier = this._modeService.getLanguageIdentifier(languageId);
if (languageIdentifier) {
const langName = languageIdentifier.language;
this._files.forEach(file => {
// kick off loading (which is a noop in case it's already loaded)
// and optimistically collect snippets
file.load().catch(err => { /*ignore*/ });
file.select(langName, result);
});
}
return result;
}
......@@ -203,9 +210,14 @@ class SnippetsService implements ISnippetsService {
continue;
}
if (this._files.has(validContribution.location.toString())) {
this._files.get(validContribution.location.toString()).defaultScopes.push(validContribution.language);
const resource = validContribution.location.toString();
if (this._files.has(resource)) {
const file = this._files.get(resource);
if (file.defaultScopes) {
file.defaultScopes.push(validContribution.language);
} else {
file.defaultScopes = [];
}
} else {
const file = new SnippetFile(SnippetSource.Extension, validContribution.location, validContribution.language ? [validContribution.language] : undefined, extension.description, this._fileService);
this._files.set(file.location.toString(), file);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册