Skip to content

Commit 220c9fd

Browse files
committed
fix: test and comment
1 parent c074b49 commit 220c9fd

File tree

3 files changed

+13
-42
lines changed

3 files changed

+13
-42
lines changed

lib/adapters/document-sync-adapter.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ export default class DocumentSyncAdapter {
6060
* @param _editorSelector A predicate function that takes a {TextEditor} and returns a {boolean} indicating whether
6161
* this adapter should care about the contents of the editor.
6262
* @param _getLanguageIdFromEditor A function that returns a {string} of `languageId` used for `textDocument/didOpen`
63-
* notification. If {null} or {undefined} is returned, it will fall back to the editor's grammar name.
63+
* notification.
6464
*/
6565
constructor(
6666
private _connection: LanguageClientConnection,
6767
private _editorSelector: (editor: TextEditor) => boolean,
6868
documentSync: TextDocumentSyncOptions | TextDocumentSyncKind | undefined,
6969
private _reportBusyWhile: Utils.ReportBusyWhile,
70-
private _getLanguageIdFromEditor: (editor: TextEditor) => string | void | null
70+
private _getLanguageIdFromEditor: (editor: TextEditor) => string
7171
) {
7272
if (typeof documentSync === "object") {
7373
this._documentSync = documentSync
@@ -163,7 +163,7 @@ export class TextEditorSyncAdapter {
163163
private _documentSync: TextDocumentSyncOptions,
164164
private _versions: Map<string, number>,
165165
private _reportBusyWhile: Utils.ReportBusyWhile,
166-
private _getLanguageIdFromEditor: (editor: TextEditor) => string | void | null
166+
private _getLanguageIdFromEditor: (editor: TextEditor) => string
167167
) {
168168
this._fakeDidChangeWatchedFiles = atom.project.onDidChangeFiles == null
169169

@@ -208,12 +208,9 @@ export class TextEditorSyncAdapter {
208208
this._disposable.dispose()
209209
}
210210

211-
/**
212-
* Get the languageId field that will be sent to the language server by simply using the `_getLanguageIdFromEditor`.
213-
* Fall back to the grammar name if `_getLanguageIdFromEditor` returns null or undefined.
214-
*/
211+
/** Get the languageId field that will be sent to the language server by simply using the `_getLanguageIdFromEditor`. */
215212
public getLanguageId(): string {
216-
return this._getLanguageIdFromEditor(this._editor) ?? this._editor.getGrammar().name
213+
return this._getLanguageIdFromEditor(this._editor)
217214
}
218215

219216
/**

lib/auto-languageclient.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ export default class AutoLanguageClient {
296296
}
297297

298298
/**
299-
* (Optional) Determines the `languageId` string used for `textDocument/didOpen` notification. If {null} or
300-
* {undefined} is returned, it will fall back to the {_editor}'s grammar name.
299+
* (Optional) Determines the `languageId` string used for `textDocument/didOpen` notification. The default is to use
300+
* the grammar name.
301301
*
302302
* You can override this like this:
303303
*
@@ -306,14 +306,15 @@ export default class AutoLanguageClient {
306306
* if (editor.getGrammar().scopeName === "source.myLanguage") {
307307
* return "myCustumLanguageId"
308308
* }
309+
* return super.getLanguageIdFromEditor(editor)
309310
* }
310311
* }
311312
*
312-
* @param _editor A {TextEditor} which is opened.
313+
* @param editor A {TextEditor} which is opened.
313314
* @returns A {string} of `languageId` used for `textDocument/didOpen` notification.
314315
*/
315-
protected getLanguageIdFromEditor(_editor: TextEditor): string {
316-
return this._editor.getGrammar().name
316+
protected getLanguageIdFromEditor(editor: TextEditor): string {
317+
return editor.getGrammar().name
317318
}
318319

319320
// Helper methods that are useful for implementors

test/adapters/document-sync-adapter.test.ts

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe("DocumentSyncAdapter", () => {
5454
() => false,
5555
textDocumentSync,
5656
(_t, f) => f(),
57-
() => undefined
57+
() => ""
5858
)
5959
}
6060

@@ -85,7 +85,7 @@ describe("DocumentSyncAdapter", () => {
8585
})
8686

8787
describe("getLanguageId", () => {
88-
function create(getLanguageIdFromEditor: () => string | null | void) {
88+
function create(getLanguageIdFromEditor: () => string) {
8989
return new DocumentSyncAdapter(
9090
null as any,
9191
() => false,
@@ -102,32 +102,5 @@ describe("DocumentSyncAdapter", () => {
102102
const result = adapter.getEditorSyncAdapter(editor).getLanguageId()
103103
expect(result).toBe("someLanguageId")
104104
})
105-
106-
it("fall back to the grammar name if `_getLanguageIdFromEditor` returns undefined", () => {
107-
const editor = createFakeEditor()
108-
spyOn(editor, "getGrammar").and.returnValue({ name: "testGrammarName" } as any)
109-
const adapter = create(() => undefined) as any
110-
adapter._handleNewEditor(editor)
111-
const result = adapter.getEditorSyncAdapter(editor).getLanguageId()
112-
expect(result).toBe("testGrammarName")
113-
})
114-
115-
it("fall back to the grammar name if `_getLanguageIdFromEditor` returns null", () => {
116-
const editor = createFakeEditor()
117-
spyOn(editor, "getGrammar").and.returnValue({ name: "testGrammarName" } as any)
118-
const adapter = create(() => null) as any
119-
adapter._handleNewEditor(editor)
120-
const result = adapter.getEditorSyncAdapter(editor).getLanguageId()
121-
expect(result).toBe("testGrammarName")
122-
})
123-
124-
it("don't fall back to the grammar name if `_getLanguageIdFromEditor` returns an empty string", () => {
125-
const editor = createFakeEditor()
126-
spyOn(editor, "getGrammar").and.returnValue({ name: "testGrammarName" } as any)
127-
const adapter = create(() => "") as any
128-
adapter._handleNewEditor(editor)
129-
const result = adapter.getEditorSyncAdapter(editor).getLanguageId()
130-
expect(result).toBe("")
131-
})
132105
})
133106
})

0 commit comments

Comments
 (0)