Skip to content

Commit

Permalink
Chore: Remove debounce on analyze
Browse files Browse the repository at this point in the history
  • Loading branch information
idillon-sfl committed Jan 3, 2024
1 parent 1b8a61a commit 4d73a66
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 88 deletions.
28 changes: 14 additions & 14 deletions server/src/__tests__/analyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('analyze', () => {

it('analyzes simple correct bb file', async () => {
const analyzer = await getAnalyzer()
const diagnostics = await analyzer.analyze({
const diagnostics = analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.CORRECT
})
Expand All @@ -41,7 +41,7 @@ describe('analyze', () => {

it('analyzes the document and returns global declarations', async () => {
const analyzer = await getAnalyzer()
await analyzer.analyze({
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.DECLARATION
})
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('analyze', () => {

it('analyzes the document and returns word at point', async () => {
const analyzer = await getAnalyzer()
await analyzer.analyze({
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.DECLARATION
})
Expand Down Expand Up @@ -227,10 +227,10 @@ describe('sourceIncludeFiles', () => {
const analyzer = await getAnalyzer()
const uri = FIXTURE_URI.DIRECTIVE
// analyze 4 documents before calling sourceIncludeFiles
await analyzer.analyze({ document: FIXTURE_DOCUMENT.DIRECTIVE, uri: FIXTURE_URI.DIRECTIVE })
await analyzer.analyze({ document: FIXTURE_DOCUMENT.BAR_INC, uri: FIXTURE_URI.BAR_INC })
await analyzer.analyze({ document: FIXTURE_DOCUMENT.FOO_INC, uri: FIXTURE_URI.FOO_INC })
await analyzer.analyze({ document: FIXTURE_DOCUMENT.BAZ_BBCLASS, uri: FIXTURE_URI.BAZ_BBCLASS })
analyzer.analyze({ document: FIXTURE_DOCUMENT.DIRECTIVE, uri: FIXTURE_URI.DIRECTIVE })
analyzer.analyze({ document: FIXTURE_DOCUMENT.BAR_INC, uri: FIXTURE_URI.BAR_INC })
analyzer.analyze({ document: FIXTURE_DOCUMENT.FOO_INC, uri: FIXTURE_URI.FOO_INC })
analyzer.analyze({ document: FIXTURE_DOCUMENT.BAZ_BBCLASS, uri: FIXTURE_URI.BAZ_BBCLASS })

jest.spyOn(Analyzer.prototype, 'getDirectiveFileUris').mockReturnValueOnce([
FIXTURE_URI.BAR_INC,
Expand Down Expand Up @@ -261,10 +261,10 @@ describe('sourceIncludeFiles', () => {
const analyzer = await getAnalyzer()
const uri = FIXTURE_URI.DIRECTIVE

await analyzer.analyze({ document: FIXTURE_DOCUMENT.DIRECTIVE, uri: FIXTURE_URI.DIRECTIVE })
await analyzer.analyze({ document: FIXTURE_DOCUMENT.BAR_INC, uri: FIXTURE_URI.BAR_INC })
await analyzer.analyze({ document: FIXTURE_DOCUMENT.FOO_INC, uri: FIXTURE_URI.FOO_INC })
await analyzer.analyze({ document: FIXTURE_DOCUMENT.BAZ_BBCLASS, uri: FIXTURE_URI.BAZ_BBCLASS })
analyzer.analyze({ document: FIXTURE_DOCUMENT.DIRECTIVE, uri: FIXTURE_URI.DIRECTIVE })
analyzer.analyze({ document: FIXTURE_DOCUMENT.BAR_INC, uri: FIXTURE_URI.BAR_INC })
analyzer.analyze({ document: FIXTURE_DOCUMENT.FOO_INC, uri: FIXTURE_URI.FOO_INC })
analyzer.analyze({ document: FIXTURE_DOCUMENT.BAZ_BBCLASS, uri: FIXTURE_URI.BAZ_BBCLASS })

jest.spyOn(Analyzer.prototype, 'getDirectiveFileUris').mockReturnValueOnce([
FIXTURE_URI.BAR_INC,
Expand Down Expand Up @@ -363,7 +363,7 @@ describe('declarations', () => {
const document = FIXTURE_DOCUMENT.COMPLETION
const uri = FIXTURE_URI.COMPLETION

await analyzer.analyze({
analyzer.analyze({
document,
uri
})
Expand All @@ -387,7 +387,7 @@ describe('getLinksInStringContent', () => {
const document = FIXTURE_DOCUMENT.CORRECT
const uri = FIXTURE_URI.CORRECT

await analyzer.analyze({
analyzer.analyze({
document,
uri
})
Expand All @@ -412,7 +412,7 @@ describe('getLinksInStringContent', () => {
const document = FIXTURE_DOCUMENT.CORRECT
const uri = FIXTURE_URI.CORRECT

await analyzer.analyze({
analyzer.analyze({
document,
uri
})
Expand Down
20 changes: 10 additions & 10 deletions server/src/__tests__/completions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe('On Completion', () => {
})

it("doesn't provide suggestions when it is pure string content", async () => {
await analyzer.analyze({
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.COMPLETION
})
Expand All @@ -197,7 +197,7 @@ describe('On Completion', () => {
})

it("doesn't provide duplicate completion items for local custom variables", async () => {
await analyzer.analyze({
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.COMPLETION
})
Expand All @@ -223,7 +223,7 @@ describe('On Completion', () => {
})

it('provides necessary suggestions when it is in variable expansion', async () => {
await analyzer.analyze({
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.COMPLETION
})
Expand Down Expand Up @@ -269,7 +269,7 @@ describe('On Completion', () => {
})
// TODO: Add tests for the second and other overrides that come after. e.g. VAR:override1:override2:over... And it is better after the tree-sitter library can properly handle it as mentioned in the issue: https://github.com/amaanq/tree-sitter-bitbake/issues/9
it('provides suggestions for operators when a ":" is typed and it follows an identifier or in the middle of typing such syntax', async () => {
await analyzer.analyze({
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.COMPLETION
})
Expand Down Expand Up @@ -353,7 +353,7 @@ describe('On Completion', () => {
})

it('provides suggestions for overrides when a ":" is typed and it follows an identifier', async () => {
await analyzer.analyze({
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.COMPLETION
})
Expand Down Expand Up @@ -383,7 +383,7 @@ describe('On Completion', () => {
})

it('provides no suggestions when a ":" is typed but it is not part of a valid override syntax', async () => {
await analyzer.analyze({
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.COMPLETION
})
Expand All @@ -402,7 +402,7 @@ describe('On Completion', () => {
})

it('provides suggestions for variable flags when a "[" is typed and it follows an identifier (Before and After scanning docs', async () => {
await analyzer.analyze({
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.COMPLETION
})
Expand Down Expand Up @@ -458,7 +458,7 @@ describe('On Completion', () => {
})

it('provides no suggestions when a "[" is typed but it doesn\'t follow a bitbake identifier', async () => {
await analyzer.analyze({
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.COMPLETION
})
Expand Down Expand Up @@ -541,7 +541,7 @@ describe('On Completion', () => {
}
}]

await analyzer.analyze({
analyzer.analyze({
uri: documentUri,
document: FIXTURE_DOCUMENT.COMPLETION
})
Expand Down Expand Up @@ -648,7 +648,7 @@ describe('On Completion', () => {
_recipes: []
}

await analyzer.analyze({
analyzer.analyze({
uri: FIXTURE_URI.DIRECTIVE,
document: FIXTURE_DOCUMENT.DIRECTIVE
})
Expand Down
6 changes: 3 additions & 3 deletions server/src/__tests__/definition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('on definition', () => {
_recipes: []
}

await analyzer.analyze({
analyzer.analyze({
uri: FIXTURE_URI.DIRECTIVE,
document: FIXTURE_DOCUMENT.DIRECTIVE
})
Expand Down Expand Up @@ -119,7 +119,7 @@ describe('on definition', () => {
]
}

await analyzer.analyze({
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.DIRECTIVE
})
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('on definition', () => {
}
]

await analyzer.analyze({
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.DIRECTIVE
})
Expand Down
4 changes: 2 additions & 2 deletions server/src/__tests__/embedded-languages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Embedded Language Documents file management', () => {

it('generate, rename and delete embedded language documents', async () => {
// Setup
await analyzer.analyze({
analyzer.analyze({
uri: FIXTURE_DOCUMENT.EMBEDDED.uri,
document: FIXTURE_DOCUMENT.EMBEDDED
})
Expand Down Expand Up @@ -198,7 +198,7 @@ describe('Create Python embedded language content with inline Python', () => {
const createEmbeddedContent = async (content: string, language: EmbeddedLanguageType): Promise<string | undefined> => {
const uri = randomUUID()
const document = TextDocument.create(uri, 'bitbake', 1, content)
await analyzer.analyze({ document, uri })
analyzer.analyze({ document, uri })
await generateEmbeddedLanguageDocs(document)
const pythonEmbeddedLanguageDocInfos = embeddedLanguageDocsManager.getEmbeddedLanguageDocInfos(uri, language)
if (pythonEmbeddedLanguageDocInfos === undefined) {
Expand Down
12 changes: 6 additions & 6 deletions server/src/__tests__/hover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('on hover', () => {

it('shows definition on hovering variable in variable assignment syntax or in variable expansion syntax after scanning the docs', async () => {
bitBakeDocScanner.parseBitbakeVariablesFile()
await analyzer.analyze({
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.HOVER
})
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('on hover', () => {

it('should show hover definition for variable flags after scanning the docs', async () => {
bitBakeDocScanner.parseVariableFlagFile()
await analyzer.analyze({
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.HOVER
})
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('on hover', () => {

it('should show hover definition for yocto tasks after scanning the docs', async () => {
bitBakeDocScanner.parseYoctoTaskFile()
await analyzer.analyze({
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.HOVER
})
Expand Down Expand Up @@ -258,7 +258,7 @@ describe('on hover', () => {
})

it('should show hover definition for keywords', async () => {
await analyzer.analyze({
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.HOVER
})
Expand Down Expand Up @@ -321,7 +321,7 @@ describe('on hover', () => {
it('shows definition on hovering variable in Python functions for accessing datastore', async () => {
bitBakeDocScanner.parseBitbakeVariablesFile()
bitBakeDocScanner.parsePythonDatastoreFunction()
await analyzer.analyze({
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.HOVER
})
Expand Down Expand Up @@ -490,7 +490,7 @@ describe('on hover', () => {
_recipes: []
}

await analyzer.analyze({
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.DIRECTIVE
})
Expand Down
2 changes: 1 addition & 1 deletion server/src/__tests__/semanticTokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('Semantic tokens', () => {
})

it('gives approriate semantic tokens to symbols', async () => {
await analyzer.analyze({
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.SEMANTIC_TOKENS
})
Expand Down
4 changes: 2 additions & 2 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ connection.onInitialize(async (params: InitializeParams): Promise<InitializeResu

bitBakeProjectScannerClient.onChange.on('scanReady', () => {
logger.debug('[On scanReady] Analyzing the current document again...')
void analyzer.analyze({ document: currentActiveTextDocument, uri: currentActiveTextDocument.uri })
analyzer.analyze({ document: currentActiveTextDocument, uri: currentActiveTextDocument.uri })
})

return {
Expand Down Expand Up @@ -134,7 +134,7 @@ documents.onDidChangeContent(async (event) => {
const textDocument = event.document

if (textDocument.getText().length > 0) {
const diagnostics = await analyzer.analyze({ document: textDocument, uri: textDocument.uri })
const diagnostics = analyzer.analyze({ document: textDocument, uri: textDocument.uri })
void generateEmbeddedLanguageDocs(event.document)
void connection.sendDiagnostics({ uri: textDocument.uri, diagnostics })
}
Expand Down
17 changes: 4 additions & 13 deletions server/src/tree-sitter/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
import type Parser from 'web-tree-sitter'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { type EmbeddedRegions, getEmbeddedRegionsFromNode, getGlobalDeclarationsAndComments, type GlobalDeclarations, type GlobalSymbolComments } from './declarations'
import { debounce } from '../utils/async'
import { type Tree } from 'web-tree-sitter'
import * as TreeSitterUtils from './utils'
import { type DirectiveStatementKeyword } from '../lib/src/types/directiveKeywords'
Expand All @@ -28,7 +27,6 @@ import fs from 'fs'
import path from 'path'
import { bitBakeProjectScannerClient } from '../BitbakeProjectScannerClient'
import { bitBakeDocScanner } from '../BitBakeDocScanner'
const DEBOUNCE_TIME_MS = 500

interface AnalyzedDocument {
document: TextDocument
Expand All @@ -43,7 +41,6 @@ interface AnalyzedDocument {
export default class Analyzer {
private parser?: Parser
private uriToAnalyzedDocument: Record<string, AnalyzedDocument | undefined> = {}
private debouncedExecuteAnalyzation?: ReturnType<typeof debounce>

public getDocumentTexts (uri: string): string[] | undefined {
return this.uriToAnalyzedDocument[uri]?.document.getText().split(/\r?\n/g)
Expand All @@ -61,16 +58,16 @@ export default class Analyzer {
this.parser = parser
}

public async analyze ({
public analyze ({
document,
uri
}: {
document: TextDocument
uri: string
}): Promise<Diagnostic[]> {
}): Diagnostic[] {
if (this.parser === undefined) {
logger.debug('[Analyzer] The analyzer is not initialized with a parser')
return await Promise.resolve([])
return []
}

const fileContent = document.getText()
Expand All @@ -95,13 +92,7 @@ export default class Analyzer {
extraSymbols
}

let debouncedExecuteAnalyzation = this.debouncedExecuteAnalyzation
if (debouncedExecuteAnalyzation === undefined) {
debouncedExecuteAnalyzation = debounce(this.executeAnalyzation.bind(this), DEBOUNCE_TIME_MS)
this.debouncedExecuteAnalyzation = debouncedExecuteAnalyzation
}

return await debouncedExecuteAnalyzation(document, uri, tree)
return this.executeAnalyzation(document, uri, tree)
}

private executeAnalyzation (document: TextDocument, uri: string, tree: Tree): Diagnostic[] {
Expand Down
37 changes: 0 additions & 37 deletions server/src/utils/async.ts

This file was deleted.

0 comments on commit 4d73a66

Please sign in to comment.