Skip to content

Commit

Permalink
Merge branch 'release-0.66.0' of https://github.com/rokucommunity/bri…
Browse files Browse the repository at this point in the history
…ghterscript into release-0.66.0
  • Loading branch information
TwitchBronBron committed Aug 1, 2023
2 parents 1fe7d42 + 0e0e197 commit a47285e
Show file tree
Hide file tree
Showing 10 changed files with 1,632 additions and 1,561 deletions.
692 changes: 2 additions & 690 deletions src/Program.spec.ts

Large diffs are not rendered by default.

61 changes: 2 additions & 59 deletions src/Program.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import * as assert from 'assert';
import * as fsExtra from 'fs-extra';
import * as path from 'path';
import type { CodeAction, CompletionItem, Position, Range, SignatureInformation, Location } from 'vscode-languageserver';
import { CompletionItemKind } from 'vscode-languageserver';
import type { CodeAction, Position, Range, SignatureInformation, Location } from 'vscode-languageserver';
import type { BsConfig } from './BsConfig';
import { Scope } from './Scope';
import { DiagnosticMessages } from './DiagnosticMessages';
import { BrsFile } from './files/BrsFile';
import { XmlFile } from './files/XmlFile';
import type { BsDiagnostic, File, FileReference, FileObj, BscFile, SemanticToken, AfterFileTranspileEvent, FileLink, ProvideHoverEvent, ProvideCompletionsEvent, Hover, BeforeFileParseEvent } from './interfaces';
import type { BsDiagnostic, File, FileObj, BscFile, SemanticToken, AfterFileTranspileEvent, FileLink, ProvideHoverEvent, ProvideCompletionsEvent, Hover, BeforeFileParseEvent } from './interfaces';
import { standardizePath as s, util } from './util';
import { XmlScope } from './XmlScope';
import { DiagnosticFilterer } from './DiagnosticFilterer';
Expand Down Expand Up @@ -1019,62 +1018,6 @@ export class Program {
return file.getReferences(position);
}

/**
* Get a list of all script imports, relative to the specified pkgPath
* @param sourcePkgPath - the pkgPath of the source that wants to resolve script imports.
*/
public getScriptImportCompletions(sourcePkgPath: string, scriptImport: FileReference) {
let lowerSourcePkgPath = sourcePkgPath.toLowerCase();

let result = [] as CompletionItem[];
/**
* hashtable to prevent duplicate results
*/
let resultPkgPaths = {} as Record<string, boolean>;

//restrict to only .brs files
for (let key in this.files) {
let file = this.files[key];
if (
//is a BrightScript or BrighterScript file
(file.extension === '.bs' || file.extension === '.brs') &&
//this file is not the current file
lowerSourcePkgPath !== file.pkgPath.toLowerCase()
) {
//add the relative path
let relativePath = util.getRelativePath(sourcePkgPath, file.pkgPath).replace(/\\/g, '/');
let pkgPathStandardized = file.pkgPath.replace(/\\/g, '/');
let filePkgPath = `pkg:/${pkgPathStandardized}`;
let lowerFilePkgPath = filePkgPath.toLowerCase();
if (!resultPkgPaths[lowerFilePkgPath]) {
resultPkgPaths[lowerFilePkgPath] = true;

result.push({
label: relativePath,
detail: file.srcPath,
kind: CompletionItemKind.File,
textEdit: {
newText: relativePath,
range: scriptImport.filePathRange
}
});

//add the absolute path
result.push({
label: filePkgPath,
detail: file.srcPath,
kind: CompletionItemKind.File,
textEdit: {
newText: filePkgPath,
range: scriptImport.filePathRange
}
});
}
}
}
return result;
}

/**
* Transpile a single file and get the result as a string.
* This does not write anything to the file system.
Expand Down
11 changes: 0 additions & 11 deletions src/Scope.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Position, Range } from 'vscode-languageserver';
import util, { standardizePath as s } from './util';
import { DiagnosticMessages } from './DiagnosticMessages';
import { Program } from './Program';
import { ParseMode } from './parser/Parser';
import PluginInterface from './PluginInterface';
import { expectDiagnostics, expectDiagnosticsIncludes, expectTypeToBe, expectZeroDiagnostics, trim } from './testHelpers.spec';
import { Logger } from './Logger';
Expand Down Expand Up @@ -2040,16 +2039,6 @@ describe('Scope', () => {
});
});

describe('getCallablesAsCompletions', () => {
it('returns documentation when possible', () => {
let completions = program.globalScope.getCallablesAsCompletions(ParseMode.BrightScript);
//it should find the completions for the global scope
expect(completions).to.be.length.greaterThan(0);
//it should find documentation for completions
expect(completions.filter(x => !!x.documentation)).to.have.length.greaterThan(0);
});
});

describe('buildNamespaceLookup', () => {
it('does not crash when class statement is missing `name` prop', () => {
program.setFile<BrsFile>('source/main.bs', `
Expand Down
72 changes: 2 additions & 70 deletions src/Scope.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/dot-notation */
import type { CompletionItem, Position, Range, Location } from 'vscode-languageserver';
import type { Position, Range, Location } from 'vscode-languageserver';
import * as path from 'path';
import { CompletionItemKind } from 'vscode-languageserver';
import chalk from 'chalk';
import type { DiagnosticInfo } from './DiagnosticMessages';
import { DiagnosticMessages } from './DiagnosticMessages';
Expand All @@ -18,7 +17,7 @@ import { URI } from 'vscode-uri';
import { LogLevel } from './Logger';
import type { BrsFile } from './files/BrsFile';
import type { DependencyGraph, DependencyChangedEvent } from './DependencyGraph';
import { isBrsFile, isMethodStatement, isClassStatement, isConstStatement, isEnumStatement, isFunctionStatement, isXmlFile, isEnumMemberStatement, isNamespaceStatement, isNamespaceType, isReferenceType, isCallableType } from './astUtils/reflection';
import { isBrsFile, isClassStatement, isConstStatement, isEnumStatement, isFunctionStatement, isXmlFile, isEnumMemberStatement, isNamespaceStatement, isNamespaceType, isReferenceType, isCallableType } from './astUtils/reflection';
import { SymbolTable, SymbolTypeFlag } from './SymbolTable';
import type { Statement } from './parser/AstNode';
import type { BscType } from './types/BscType';
Expand Down Expand Up @@ -1171,40 +1170,6 @@ export class Scope {
return hasFile;
}

/**
* Get all callables as completionItems
*/
public getCallablesAsCompletions(parseMode: ParseMode) {
let completions = [] as CompletionItem[];
let callables = this.getAllCallables();

if (parseMode === ParseMode.BrighterScript) {
//throw out the namespaced callables (they will be handled by another method)
callables = callables.filter(x => x.callable.hasNamespace === false);
}

for (let callableContainer of callables) {
completions.push(this.createCompletionFromCallable(callableContainer));
}
return completions;
}

public createCompletionFromCallable(callableContainer: CallableContainer): CompletionItem {
return {
label: callableContainer.callable.getName(ParseMode.BrighterScript),
kind: CompletionItemKind.Function,
detail: callableContainer.callable.shortDescription,
documentation: callableContainer.callable.documentation ? { kind: 'markdown', value: callableContainer.callable.documentation } : undefined
};
}

public createCompletionFromFunctionStatement(statement: FunctionStatement): CompletionItem {
return {
label: statement.getName(ParseMode.BrighterScript),
kind: CompletionItemKind.Function
};
}

/**
* Get the definition (where was this thing first defined) of the symbol under the position
*/
Expand All @@ -1213,39 +1178,6 @@ export class Scope {
return [];
}

/**
* Scan all files for property names, and return them as completions
*/
public getPropertyNameCompletions() {
let results = [] as CompletionItem[];
this.enumerateBrsFiles((file) => {
results.push(...file.propertyNameCompletions);
});
return results;
}

public getAllClassMemberCompletions() {
let results = new Map<string, CompletionItem>();
let filesSearched = new Set<BscFile>();
for (const file of this.getAllFiles()) {
if (isXmlFile(file) || filesSearched.has(file)) {
continue;
}
filesSearched.add(file);
for (let cs of file.parser.references.classStatements) {
for (let s of [...cs.methods, ...cs.fields]) {
if (!results.has(s.name.text) && s.name.text.toLowerCase() !== 'new') {
results.set(s.name.text, {
label: s.name.text,
kind: isMethodStatement(s) ? CompletionItemKind.Method : CompletionItemKind.Field
});
}
}
}
}
return results;
}

/**
* @param className - The name of the class (including namespace if possible)
* @param callsiteNamespace - the name of the namespace where the call site resides (this is NOT the known namespace of the class).
Expand Down
Loading

0 comments on commit a47285e

Please sign in to comment.