Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into namespace-validations
  • Loading branch information
TwitchBronBron committed Jul 11, 2022
2 parents f9012e5 + 9e6e03b commit f6e12f8
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/Program.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assert, expect } from 'chai';
import * as pick from 'object.pick';
import * as sinonImport from 'sinon';
import { CompletionItemKind, Position, Range, Location } from 'vscode-languageserver';
import { CompletionItemKind, Position, Range } from 'vscode-languageserver';
import * as fsExtra from 'fs-extra';
import { DiagnosticMessages } from './DiagnosticMessages';
import type { BrsFile } from './files/BrsFile';
Expand Down Expand Up @@ -232,7 +232,7 @@ describe('Program', () => {
...DiagnosticMessages.duplicateComponentName('Component1'),
range: Range.create(1, 17, 1, 27),
relatedInformation: [{
location: Location.create(
location: util.createLocation(
URI.file(s`${rootDir}/components/component1.xml`).toString(),
Range.create(1, 17, 1, 27)
),
Expand All @@ -242,7 +242,7 @@ describe('Program', () => {
...DiagnosticMessages.duplicateComponentName('Component1'),
range: Range.create(1, 17, 1, 27),
relatedInformation: [{
location: Location.create(
location: util.createLocation(
URI.file(s`${rootDir}/components/component2.xml`).toString(),
Range.create(1, 17, 1, 27)
),
Expand Down
6 changes: 3 additions & 3 deletions src/Program.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as assert from 'assert';
import * as fsExtra from 'fs-extra';
import * as path from 'path';
import type { CodeAction, CompletionItem, Position, Range, SignatureInformation } from 'vscode-languageserver';
import { Location, CompletionItemKind } from 'vscode-languageserver';
import type { CodeAction, CompletionItem, Position, Range, SignatureInformation, Location } from 'vscode-languageserver';
import { CompletionItemKind } from 'vscode-languageserver';
import type { BsConfig } from './BsConfig';
import { Scope } from './Scope';
import { DiagnosticMessages } from './DiagnosticMessages';
Expand Down Expand Up @@ -677,7 +677,7 @@ export class Program {
file: xmlFile,
relatedInformation: xmlFiles.filter(x => x !== xmlFile).map(x => {
return {
location: Location.create(
location: util.createLocation(
URI.file(xmlFile.srcPath ?? xmlFile.srcPath).toString(),
x.componentName.range
),
Expand Down
8 changes: 4 additions & 4 deletions src/Scope.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CompletionItem, Position, Range } from 'vscode-languageserver';
import type { CompletionItem, Position, Range, Location } from 'vscode-languageserver';
import * as path from 'path';
import { CompletionItemKind, Location } from 'vscode-languageserver';
import { CompletionItemKind } from 'vscode-languageserver';
import chalk from 'chalk';
import type { DiagnosticInfo } from './DiagnosticMessages';
import { DiagnosticMessages } from './DiagnosticMessages';
Expand Down Expand Up @@ -686,7 +686,7 @@ export class Scope {
range: param.name.range,
relatedInformation: [{
message: 'Namespace declared here',
location: Location.create(
location: util.createLocation(
URI.file(namespace.file.srcPath).toString(),
namespace.nameRange
)
Expand All @@ -707,7 +707,7 @@ export class Scope {
range: assignment.name.range,
relatedInformation: [{
message: 'Namespace declared here',
location: Location.create(
location: util.createLocation(
URI.file(namespace.file.srcPath).toString(),
namespace.nameRange
)
Expand Down
7 changes: 3 additions & 4 deletions src/bscPlugin/validation/ScopeValidator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { DiagnosticRelatedInformation, Position } from 'vscode-languageserver';
import { Location } from 'vscode-languageserver';
import { URI } from 'vscode-uri';
import { isBrsFile, isCallExpression, isLiteralExpression, isNewExpression, isXmlScope } from '../../astUtils/reflection';
import { Cache } from '../../Cache';
Expand All @@ -14,6 +12,7 @@ import type { BRSComponentData } from '../../roku-types';
import type { Token } from '../../lexer/Token';
import type { Scope } from '../../Scope';
import type { SymbolTable } from '../../SymbolTable';
import type { DiagnosticRelatedInformation, Position } from 'vscode-languageserver';

/**
* The lower-case names of all platform-included scenegraph nodes
Expand Down Expand Up @@ -175,7 +174,7 @@ export class ScopeValidator {
range: tokens[tokens.length - 1].range,
relatedInformation: [{
message: 'Enum declared here',
location: Location.create(
location: util.createLocation(
URI.file(file.srcPath).toString(),
theEnum.tokens.name.range
)
Expand Down Expand Up @@ -248,7 +247,7 @@ export class ScopeValidator {
range: duplicateEnumInfo.statement.tokens.name.range,
relatedInformation: [{
message: 'Enum declared here',
location: Location.create(
location: util.createLocation(
URI.file(primaryEnum.file.srcPath).toString(),
primaryEnum.statement.tokens.name.range
)
Expand Down
22 changes: 11 additions & 11 deletions src/files/BrsFile.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CodeWithSourceMap } from 'source-map';
import { SourceNode } from 'source-map';
import type { CompletionItem, Hover, Position } from 'vscode-languageserver';
import { CompletionItemKind, SymbolKind, Location, SignatureInformation, ParameterInformation, DocumentSymbol, SymbolInformation, TextEdit } from 'vscode-languageserver';
import type { CompletionItem, Hover, Position, Location } from 'vscode-languageserver';
import { CompletionItemKind, SymbolKind, SignatureInformation, ParameterInformation, DocumentSymbol, SymbolInformation, TextEdit } from 'vscode-languageserver';
import chalk from 'chalk';
import * as path from 'path';
import type { Scope } from '../Scope';
Expand Down Expand Up @@ -1106,7 +1106,7 @@ export class BrsFile {
const namespaceItemStatementHandler = (statement: ClassStatement | FunctionStatement) => {
if (!location && statement.name.text.toLowerCase() === endName) {
const uri = util.pathToUri(file.srcPath);
location = Location.create(uri, statement.range);
location = util.createLocation(uri, statement.range);
}
};

Expand Down Expand Up @@ -1422,7 +1422,7 @@ export class BrsFile {
//to only get functions defined in interface methods
const callable = scope.getAllCallables().find((c) => c.callable.name.toLowerCase() === textToSearchFor); // eslint-disable-line @typescript-eslint/no-loop-func
if (callable) {
results.push(Location.create(util.pathToUri((callable.callable.file as BrsFile).srcPath), callable.callable.functionStatement.range));
results.push(util.createLocation(util.pathToUri((callable.callable.file as BrsFile).srcPath), callable.callable.functionStatement.range));
}
}
return results;
Expand All @@ -1435,7 +1435,7 @@ export class BrsFile {
const nameParts = cs.parentClassName.getNameParts();
let extendedClass = this.getClassFileLink(nameParts[nameParts.length - 1], nameParts.slice(0, -1).join('.'));
if (extendedClass) {
results.push(Location.create(util.pathToUri(extendedClass.file.srcPath), extendedClass.item.range));
results.push(util.createLocation(util.pathToUri(extendedClass.file.srcPath), extendedClass.item.range));
}
}
return results;
Expand All @@ -1460,14 +1460,14 @@ export class BrsFile {
//we found a variable declaration with this token text!
if (varDeclaration.name.toLowerCase() === textToSearchFor) {
const uri = util.pathToUri(this.srcPath);
results.push(Location.create(uri, varDeclaration.nameRange));
results.push(util.createLocation(uri, varDeclaration.nameRange));
}
}
if (this.tokenFollows(token, TokenKind.Goto)) {
for (const label of functionScope.labelStatements) {
if (label.name.toLocaleLowerCase() === textToSearchFor) {
const uri = util.pathToUri(this.srcPath);
results.push(Location.create(uri, label.nameRange));
results.push(util.createLocation(uri, label.nameRange));
}
}
}
Expand All @@ -1492,7 +1492,7 @@ export class BrsFile {
const statementHandler = (statement: FunctionStatement) => {
if (statement.getName(this.parseMode).toLowerCase() === textToSearchFor) {
const uri = util.pathToUri(file.srcPath);
results.push(Location.create(uri, statement.range));
results.push(util.createLocation(uri, statement.range));
}
};

Expand All @@ -1511,12 +1511,12 @@ export class BrsFile {
//get class fields and members
const statementHandler = (statement: MethodStatement) => {
if (statement.getName(file.parseMode).toLowerCase() === textToSearchFor) {
results.push(Location.create(util.pathToUri(file.srcPath), statement.range));
results.push(util.createLocation(util.pathToUri(file.srcPath), statement.range));
}
};
const fieldStatementHandler = (statement: FieldStatement) => {
if (statement.name.text.toLowerCase() === textToSearchFor) {
results.push(Location.create(util.pathToUri(file.srcPath), statement.range));
results.push(util.createLocation(util.pathToUri(file.srcPath), statement.range));
}
};
file.parser.ast.walk(createVisitor({
Expand Down Expand Up @@ -1768,7 +1768,7 @@ export class BrsFile {
file.ast.walk(createVisitor({
VariableExpression: (e) => {
if (e.name.text.toLowerCase() === searchFor) {
locations.push(Location.create(util.pathToUri(file.srcPath), e.range));
locations.push(util.createLocation(util.pathToUri(file.srcPath), e.range));
}
}
}), {
Expand Down
6 changes: 3 additions & 3 deletions src/parser/tests/statement/Enum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { EnumStatement, InterfaceStatement } from '../../Statement';
import { Program } from '../../../Program';
import { createSandbox } from 'sinon';
import type { BrsFile } from '../../../files/BrsFile';
import { Location, CancellationTokenSource, CompletionItemKind } from 'vscode-languageserver-protocol';
import { CancellationTokenSource, CompletionItemKind } from 'vscode-languageserver-protocol';
import { WalkMode } from '../../../astUtils/visitors';
import { isEnumStatement } from '../../../astUtils/reflection';
import { URI } from 'vscode-uri';
Expand Down Expand Up @@ -216,7 +216,7 @@ describe('EnumStatement', () => {
expectDiagnostics(program, [{
...DiagnosticMessages.duplicateEnumDeclaration('source', 'Direction'),
relatedInformation: [{
location: Location.create(
location: util.createLocation(
URI.file(s`${rootDir}/source/main.bs`).toString(),
util.createRange(1, 21, 1, 30)
),
Expand All @@ -240,7 +240,7 @@ describe('EnumStatement', () => {
expectDiagnostics(program, [{
...DiagnosticMessages.duplicateEnumDeclaration('source', 'Direction'),
relatedInformation: [{
location: Location.create(
location: util.createLocation(
URI.file(s`${rootDir}/source/lib.bs`).toString(),
util.createRange(1, 21, 1, 30)
),
Expand Down
6 changes: 3 additions & 3 deletions src/validators/ClassValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DiagnosticMessages } from '../DiagnosticMessages';
import type { CallExpression } from '../parser/Expression';
import { ParseMode } from '../parser/Parser';
import type { ClassStatement, MethodStatement } from '../parser/Statement';
import { CancellationTokenSource, Location } from 'vscode-languageserver';
import { CancellationTokenSource } from 'vscode-languageserver';
import { URI } from 'vscode-uri';
import util from '../util';
import { isCallExpression, isClassFieldStatement, isClassMethodStatement, isCustomType } from '../astUtils/reflection';
Expand Down Expand Up @@ -97,7 +97,7 @@ export class BsClassValidator {
file: classStatement.file,
range: classStatement.name.range,
relatedInformation: [{
location: Location.create(
location: util.createLocation(
URI.file(nonNamespaceClass.file.srcPath).toString(),
nonNamespaceClass.name.range
),
Expand Down Expand Up @@ -371,7 +371,7 @@ export class BsClassValidator {
file: file,
range: classStatement.name.range,
relatedInformation: [{
location: Location.create(
location: util.createLocation(
URI.file(alreadyDefinedClass.file.srcPath).toString(),
this.classes.get(lowerName).range
),
Expand Down

0 comments on commit f6e12f8

Please sign in to comment.