mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
[html] more strict null preparations (but still disabled, due to dependencies)
This commit is contained in:
parent
c656d5e1d7
commit
b0e058ea98
|
@ -39,7 +39,7 @@ let documents: TextDocuments = new TextDocuments();
|
|||
// for open, change and close text document events
|
||||
documents.listen(connection);
|
||||
|
||||
let workspacePath: string;
|
||||
let workspacePath: string | undefined | null;
|
||||
var languageModes: LanguageModes;
|
||||
|
||||
let clientSnippetSupport = false;
|
||||
|
@ -53,7 +53,7 @@ documents.onDidClose(e => {
|
|||
delete documentSettings[e.document.uri];
|
||||
});
|
||||
|
||||
function getDocumentSettings(textDocument: TextDocument, needsDocumentSettings: () => boolean): Thenable<Settings> {
|
||||
function getDocumentSettings(textDocument: TextDocument, needsDocumentSettings: () => boolean): Thenable<Settings | undefined> {
|
||||
if (scopedSettingsSupport && needsDocumentSettings()) {
|
||||
let promise = documentSettings[textDocument.uri];
|
||||
if (!promise) {
|
||||
|
@ -83,7 +83,7 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
|
|||
});
|
||||
|
||||
function hasClientCapability(...keys: string[]) {
|
||||
let c = params.capabilities;
|
||||
let c = <any>params.capabilities;
|
||||
for (let i = 0; c && i < keys.length; i++) {
|
||||
c = c[keys[i]];
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
|
|||
let capabilities: ServerCapabilities & CPServerCapabilities = {
|
||||
// Tell the client that the server works in FULL text document sync mode
|
||||
textDocumentSync: documents.syncKind,
|
||||
completionProvider: clientSnippetSupport ? { resolveProvider: true, triggerCharacters: ['.', ':', '<', '"', '=', '/', '>'] } : null,
|
||||
completionProvider: clientSnippetSupport ? { resolveProvider: true, triggerCharacters: ['.', ':', '<', '"', '=', '/', '>'] } : undefined,
|
||||
hoverProvider: true,
|
||||
documentHighlightProvider: true,
|
||||
documentRangeFormattingProvider: false,
|
||||
|
@ -111,7 +111,7 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
|
|||
return { capabilities };
|
||||
});
|
||||
|
||||
let formatterRegistration: Thenable<Disposable> = null;
|
||||
let formatterRegistration: Thenable<Disposable> | null = null;
|
||||
|
||||
// The settings have changed. Is send on server activation as well.
|
||||
connection.onDidChangeConfiguration((change) => {
|
||||
|
@ -198,11 +198,12 @@ connection.onCompletion(async textDocumentPosition => {
|
|||
let document = documents.get(textDocumentPosition.textDocument.uri);
|
||||
let mode = languageModes.getModeAtPosition(document, textDocumentPosition.position);
|
||||
if (mode && mode.doComplete) {
|
||||
let doComplete = mode.doComplete;
|
||||
if (mode.getId() !== 'html') {
|
||||
connection.telemetry.logEvent({ key: 'html.embbedded.complete', value: { languageId: mode.getId() } });
|
||||
}
|
||||
let settings = await getDocumentSettings(document, () => mode.doComplete.length > 2);
|
||||
return mode.doComplete(document, textDocumentPosition.position, settings);
|
||||
let settings = await getDocumentSettings(document, () => doComplete.length > 2);
|
||||
return doComplete(document, textDocumentPosition.position, settings);
|
||||
}
|
||||
return { isIncomplete: true, items: [] };
|
||||
});
|
||||
|
|
|
@ -28,8 +28,8 @@ interface EmbeddedRegion { languageId: string; start: number; end: number; attri
|
|||
export function getDocumentRegions(languageService: LanguageService, document: TextDocument): HTMLDocumentRegions {
|
||||
let regions: EmbeddedRegion[] = [];
|
||||
let scanner = languageService.createScanner(document.getText());
|
||||
let lastTagName: string;
|
||||
let lastAttributeName: string | null;
|
||||
let lastTagName: string = '';
|
||||
let lastAttributeName: string | null = null;
|
||||
let languageIdFromType: string | undefined = undefined;
|
||||
let importedScripts: string[] = [];
|
||||
|
||||
|
@ -45,7 +45,7 @@ export function getDocumentRegions(languageService: LanguageService, document: T
|
|||
regions.push({ languageId: 'css', start: scanner.getTokenOffset(), end: scanner.getTokenEnd() });
|
||||
break;
|
||||
case TokenType.Script:
|
||||
regions.push({ languageId: languageIdFromType, start: scanner.getTokenOffset(), end: scanner.getTokenEnd() });
|
||||
regions.push({ languageId: languageIdFromType!, start: scanner.getTokenOffset(), end: scanner.getTokenEnd() });
|
||||
break;
|
||||
case TokenType.AttributeName:
|
||||
lastAttributeName = scanner.getTokenText();
|
||||
|
@ -64,7 +64,7 @@ export function getDocumentRegions(languageService: LanguageService, document: T
|
|||
languageIdFromType = void 0;
|
||||
}
|
||||
} else {
|
||||
let attributeLanguageId = getAttributeLanguage(lastAttributeName);
|
||||
let attributeLanguageId = getAttributeLanguage(lastAttributeName!);
|
||||
if (attributeLanguageId) {
|
||||
let start = scanner.getTokenOffset();
|
||||
let end = scanner.getTokenEnd();
|
||||
|
|
|
@ -53,8 +53,8 @@ export function format(languageModes: LanguageModes, document: TextDocument, for
|
|||
formatRange = Range.create(startPos, formatRange.end);
|
||||
|
||||
// perform a html format and apply changes to a new document
|
||||
let htmlMode = languageModes.getMode('html');
|
||||
let htmlEdits = htmlMode.format(document, formatRange, formattingOptions, settings);
|
||||
let htmlMode = languageModes.getMode('html')!;
|
||||
let htmlEdits = htmlMode.format!(document, formatRange, formattingOptions, settings);
|
||||
let htmlFormattedContent = applyEdits(document, htmlEdits);
|
||||
let newDocument = TextDocument.create(document.uri + '.tmp', document.languageId, document.version, htmlFormattedContent);
|
||||
try {
|
||||
|
|
|
@ -118,7 +118,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
|
|||
}
|
||||
return item;
|
||||
},
|
||||
doHover(document: TextDocument, position: Position): Hover {
|
||||
doHover(document: TextDocument, position: Position): Hover | null {
|
||||
updateCurrentTextDocument(document);
|
||||
let info = jsLanguageService.getQuickInfoAtPosition(FILE_NAME, currentTextDocument.offsetAt(position));
|
||||
if (info) {
|
||||
|
@ -130,7 +130,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
|
|||
}
|
||||
return null;
|
||||
},
|
||||
doSignatureHelp(document: TextDocument, position: Position): SignatureHelp {
|
||||
doSignatureHelp(document: TextDocument, position: Position): SignatureHelp | null {
|
||||
updateCurrentTextDocument(document);
|
||||
let signHelp = jsLanguageService.getSignatureHelpItems(FILE_NAME, currentTextDocument.offsetAt(position));
|
||||
if (signHelp) {
|
||||
|
@ -155,7 +155,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
|
|||
documentation: ts.displayPartsToString(p.documentation)
|
||||
};
|
||||
signature.label += label;
|
||||
signature.parameters.push(parameter);
|
||||
signature.parameters!.push(parameter);
|
||||
if (i < a.length - 1) {
|
||||
signature.label += ts.displayPartsToString(item.separatorDisplayParts);
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
|
|||
};
|
||||
});
|
||||
}
|
||||
return null;
|
||||
return [];
|
||||
},
|
||||
findDocumentSymbols(document: TextDocument): SymbolInformation[] {
|
||||
updateCurrentTextDocument(document);
|
||||
|
@ -214,9 +214,9 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
|
|||
items.forEach(item => collectSymbols(item));
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
return [];
|
||||
},
|
||||
findDefinition(document: TextDocument, position: Position): Definition {
|
||||
findDefinition(document: TextDocument, position: Position): Definition | null {
|
||||
updateCurrentTextDocument(document);
|
||||
let definition = jsLanguageService.getDefinitionAtPosition(FILE_NAME, currentTextDocument.offsetAt(position));
|
||||
if (definition) {
|
||||
|
@ -240,7 +240,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
|
|||
};
|
||||
});
|
||||
}
|
||||
return null;
|
||||
return [];
|
||||
},
|
||||
format(document: TextDocument, range: Range, formatParams: FormattingOptions, settings: Settings = globalSettings): TextEdit[] {
|
||||
currentTextDocument = documentRegions.get(document).getEmbeddedDocument('javascript', true);
|
||||
|
@ -276,7 +276,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
|
|||
}
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
return [];
|
||||
},
|
||||
onDocumentRemoved(document: TextDocument) {
|
||||
jsDocuments.onDocumentRemoved(document);
|
||||
|
|
|
@ -34,29 +34,29 @@ export interface LanguageMode {
|
|||
getId(): string;
|
||||
configure?: (options: Settings) => void;
|
||||
doValidation?: (document: TextDocument, settings?: Settings) => Diagnostic[];
|
||||
doComplete?: (document: TextDocument, position: Position, settings?: Settings) => CompletionList;
|
||||
doResolve?: (document: TextDocument, item: CompletionItem) => CompletionItem;
|
||||
doHover?: (document: TextDocument, position: Position) => Hover;
|
||||
doSignatureHelp?: (document: TextDocument, position: Position) => SignatureHelp;
|
||||
doComplete?: (document: TextDocument, position: Position, settings?: Settings) => CompletionList | null;
|
||||
doResolve?: (document: TextDocument, item: CompletionItem) => CompletionItem | null;
|
||||
doHover?: (document: TextDocument, position: Position) => Hover | null;
|
||||
doSignatureHelp?: (document: TextDocument, position: Position) => SignatureHelp | null;
|
||||
findDocumentHighlight?: (document: TextDocument, position: Position) => DocumentHighlight[];
|
||||
findDocumentSymbols?: (document: TextDocument) => SymbolInformation[];
|
||||
findDocumentLinks?: (document: TextDocument, documentContext: DocumentContext) => DocumentLink[];
|
||||
findDefinition?: (document: TextDocument, position: Position) => Definition;
|
||||
findDefinition?: (document: TextDocument, position: Position) => Definition | null;
|
||||
findReferences?: (document: TextDocument, position: Position) => Location[];
|
||||
format?: (document: TextDocument, range: Range, options: FormattingOptions, settings: Settings) => TextEdit[];
|
||||
findDocumentColors?: (document: TextDocument) => ColorInformation[];
|
||||
getColorPresentations?: (document: TextDocument, color: Color, range: Range) => ColorPresentation[];
|
||||
doAutoClose?: (document: TextDocument, position: Position) => string;
|
||||
doAutoClose?: (document: TextDocument, position: Position) => string | null;
|
||||
onDocumentRemoved(document: TextDocument): void;
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
export interface LanguageModes {
|
||||
getModeAtPosition(document: TextDocument, position: Position): LanguageMode;
|
||||
getModeAtPosition(document: TextDocument, position: Position): LanguageMode | undefined;
|
||||
getModesInRange(document: TextDocument, range: Range): LanguageModeRange[];
|
||||
getAllModes(): LanguageMode[];
|
||||
getAllModesInDocument(document: TextDocument): LanguageMode[];
|
||||
getMode(languageId: string): LanguageMode;
|
||||
getMode(languageId: string): LanguageMode | undefined;
|
||||
onDocumentRemoved(document: TextDocument): void;
|
||||
dispose(): void;
|
||||
}
|
||||
|
@ -83,12 +83,12 @@ export function getLanguageModes(supportedLanguages: { [languageId: string]: boo
|
|||
modes['javascript'] = getJavascriptMode(documentRegions);
|
||||
}
|
||||
return {
|
||||
getModeAtPosition(document: TextDocument, position: Position): LanguageMode {
|
||||
getModeAtPosition(document: TextDocument, position: Position): LanguageMode | undefined {
|
||||
let languageId = documentRegions.get(document).getLanguageAtPosition(position);
|
||||
if (languageId) {
|
||||
return modes[languageId];
|
||||
}
|
||||
return null;
|
||||
return void 0;
|
||||
},
|
||||
getModesInRange(document: TextDocument, range: Range): LanguageModeRange[] {
|
||||
return documentRegions.get(document).getLanguageRanges(range).map(r => {
|
||||
|
|
|
@ -14,7 +14,7 @@ suite('HTML Embedded Support', () => {
|
|||
|
||||
var htmlLanguageService = getLanguageService();
|
||||
|
||||
function assertLanguageId(value: string, expectedLanguageId: string): void {
|
||||
function assertLanguageId(value: string, expectedLanguageId: string | undefined): void {
|
||||
let offset = value.indexOf('|');
|
||||
value = value.substr(0, offset) + value.substr(offset + 1);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ suite('HTML Embedded Formatting', () => {
|
|||
function assertFormat(value: string, expected: string, options?: any, formatOptions?: FormattingOptions, message?: string): void {
|
||||
var languageModes = getLanguageModes({ css: true, javascript: true });
|
||||
if (options) {
|
||||
languageModes.getAllModes().forEach(m => m.configure(options));
|
||||
languageModes.getAllModes().forEach(m => m.configure!(options));
|
||||
}
|
||||
|
||||
let rangeStartOffset = value.indexOf('|');
|
||||
|
|
|
@ -31,7 +31,7 @@ suite('HTML Javascript Support', () => {
|
|||
let list = mode.doComplete!(document, position);
|
||||
assert.ok(list);
|
||||
|
||||
let actualLabels = list.items.map(c => c.label).sort();
|
||||
let actualLabels = list!.items.map(c => c.label).sort();
|
||||
for (let expected of expectedProposals) {
|
||||
assert.ok(actualLabels.indexOf(expected) !== -1, 'Not found:' + expected + ' is ' + actualLabels.join(', '));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue