зеркало из https://github.com/microsoft/gnls.git
use pnpm and upgrade deps (#45)
This commit is contained in:
Родитель
d453dfb246
Коммит
1169ebd703
|
@ -1,4 +1,3 @@
|
|||
package-lock.json
|
||||
node_modules
|
||||
addon/gn
|
||||
build
|
||||
|
|
|
@ -15,12 +15,16 @@ jobs:
|
|||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v3
|
||||
- name: Install Pnpm
|
||||
uses: pnpm/action-setup@v2
|
||||
with:
|
||||
version: latest
|
||||
- name: Install NodeJS
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: latest
|
||||
check-latest: true
|
||||
cache: npm
|
||||
cache: pnpm
|
||||
- name: Install Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
|
@ -39,8 +43,8 @@ jobs:
|
|||
sudo apt install -y ninja-build
|
||||
;;
|
||||
macOS)
|
||||
brew install llvm@15 ninja
|
||||
addpath "$(brew --prefix llvm@15)/bin"
|
||||
brew install llvm ninja
|
||||
addpath "$(brew --prefix llvm)/bin"
|
||||
;;
|
||||
Windows)
|
||||
choco install ninja
|
||||
|
@ -66,13 +70,13 @@ jobs:
|
|||
key: ${{ runner.os }}-${{ hashFiles('addon/deps.json') }}
|
||||
path: addon/gn
|
||||
- name: Prepare Dependencies
|
||||
run: npm ci
|
||||
run: pnpm install --frozen-lockfile
|
||||
- name: Build Debug
|
||||
run: npm run debug
|
||||
run: pnpm debug
|
||||
- name: Run Test
|
||||
run: npm test
|
||||
run: pnpm test
|
||||
- name: Build Release
|
||||
run: npm run build
|
||||
run: pnpm build
|
||||
- name: Upload Archive
|
||||
uses: actions/upload-artifact@v3
|
||||
if: ${{ runner.os == 'Linux' }}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package-lock.json
|
||||
pnpm-lock.yaml
|
||||
node_modules
|
||||
addon/gn
|
||||
build
|
||||
|
|
|
@ -36,10 +36,10 @@ enum class GNSymbolKind {
|
|||
};
|
||||
|
||||
struct GNDocumentSymbol {
|
||||
const GNSymbolKind kind = GNSymbolKind::Unknown;
|
||||
const LocationRange range;
|
||||
const std::string name;
|
||||
const LocationRange selection_range;
|
||||
GNSymbolKind kind = GNSymbolKind::Unknown;
|
||||
LocationRange range;
|
||||
std::string name;
|
||||
LocationRange selection_range;
|
||||
std::list<GNDocumentSymbol> children;
|
||||
};
|
||||
|
||||
|
@ -423,13 +423,15 @@ class GNDocument {
|
|||
case Token::EQUAL:
|
||||
case Token::PLUS_EQUALS:
|
||||
case Token::MINUS_EQUALS:
|
||||
result.emplace_back(
|
||||
result.emplace_back() =
|
||||
GNDocumentSymbol{GNSymbolKind::Variable,
|
||||
binary_op->GetRange(),
|
||||
ExpressionToString(binary_op->left()),
|
||||
binary_op->left()->GetRange(),
|
||||
{}});
|
||||
default:;
|
||||
{}};
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (const auto* function_call = node->AsFunctionCall()) {
|
||||
// Call = identifier "(" [ ExprList ] ")" [ Block ] .
|
||||
|
@ -441,7 +443,7 @@ class GNDocument {
|
|||
selection_range,
|
||||
{}};
|
||||
symbol.children = ConstructDocumentSymbolAST(function_call->block());
|
||||
result.emplace_back(symbol);
|
||||
result.emplace_back() = std::move(symbol);
|
||||
} else if (const auto* condition = node->AsCondition()) {
|
||||
// Condition = "if" "(" Expr ")" Block
|
||||
// [ "else" ( Condition | Block ) ] .
|
||||
|
@ -457,7 +459,7 @@ class GNDocument {
|
|||
elseNode->GetRange(), ConstructDocumentSymbolAST(elseNode)};
|
||||
symbol.children.emplace_back(elseSymbol);
|
||||
}
|
||||
result.emplace_back(std::move(symbol));
|
||||
result.emplace_back() = std::move(symbol);
|
||||
} else if (const auto* block = node->AsBlock()) {
|
||||
// Block = "{" [ StatementList ] "}" .
|
||||
for (const auto& statement : block->statements()) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
{
|
||||
"name": "gn",
|
||||
"repo": "https://gn.googlesource.com/gn",
|
||||
"commit": "ffeea1b1fd070cb6a8d47154a03f8523486b50a7",
|
||||
"commit": "e4702d7409069c4f12d45ea7b7f0890717ca3f4b",
|
||||
"patches": ["gn.patch"]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import type {Config} from '@jest/types'
|
||||
import type {Config} from 'jest'
|
||||
|
||||
export default <Config.InitialOptions>{
|
||||
export default {
|
||||
roots: ['<rootDir>/src'],
|
||||
transform: {'\\.tsx?$': 'ts-jest'},
|
||||
}
|
||||
} as Config
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
65
package.json
65
package.json
|
@ -22,7 +22,7 @@
|
|||
},
|
||||
"main": "./build/index.js",
|
||||
"engines": {
|
||||
"vscode": "^1.77.0"
|
||||
"vscode": "^1.83.0"
|
||||
},
|
||||
"extensionKind": [
|
||||
"workspace"
|
||||
|
@ -51,29 +51,30 @@
|
|||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^24.1.0",
|
||||
"@rollup/plugin-node-resolve": "^15.0.2",
|
||||
"@rollup/plugin-terser": "^0.4.1",
|
||||
"@rollup/plugin-typescript": "^11.1.0",
|
||||
"@types/jest": "^29.5.0",
|
||||
"@types/node": "^18.15.11",
|
||||
"@types/vscode": "^1.77.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.58.0",
|
||||
"@typescript-eslint/parser": "^5.58.0",
|
||||
"@vscode/vsce": "^2.19.0",
|
||||
"eslint": "^8.38.0",
|
||||
"jest": "^29.5.0",
|
||||
"node-addon-api": "^6.0.0",
|
||||
"node-gyp": "^9.3.1",
|
||||
"prettier": "^2.8.7",
|
||||
"rollup": "^3.20.2",
|
||||
"@rollup/plugin-commonjs": "^25.0.7",
|
||||
"@rollup/plugin-node-resolve": "^15.2.3",
|
||||
"@rollup/plugin-terser": "^0.4.4",
|
||||
"@rollup/plugin-typescript": "^11.1.5",
|
||||
"@types/jest": "^29.5.7",
|
||||
"@types/node": "^20.8.10",
|
||||
"@types/vscode": "^1.83.2",
|
||||
"@typescript-eslint/eslint-plugin": "^6.9.1",
|
||||
"@typescript-eslint/parser": "^6.9.1",
|
||||
"@vscode/vsce": "^2.22.0",
|
||||
"eslint": "^8.52.0",
|
||||
"jest": "^29.7.0",
|
||||
"node-addon-api": "^7.0.0",
|
||||
"node-gyp": "^10.0.0",
|
||||
"prettier": "^3.0.3",
|
||||
"rollup": "^4.2.0",
|
||||
"ts-jest": "^29.1.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"tslib": "^2.6.2",
|
||||
"typescript": "^5.0.4",
|
||||
"vscode-languageclient": "^8.1.0",
|
||||
"vscode-languageserver": "^8.1.0",
|
||||
"vscode-languageserver-textdocument": "^1.0.8",
|
||||
"vscode-uri": "^3.0.7"
|
||||
"vscode-languageclient": "^9.0.1",
|
||||
"vscode-languageserver": "^9.0.1",
|
||||
"vscode-languageserver-textdocument": "^1.0.11",
|
||||
"vscode-uri": "^3.0.8"
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "ts-node script prepare",
|
||||
|
@ -84,14 +85,20 @@
|
|||
"package": "ts-node script package"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"parserOptions": {
|
||||
"project": true,
|
||||
"tsconfigRootDir": "."
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
]
|
||||
"plugin:@typescript-eslint/recommended-type-checked",
|
||||
"plugin:@typescript-eslint/stylistic-type-checked"
|
||||
],
|
||||
"rules": {
|
||||
"no-undef": "off"
|
||||
}
|
||||
},
|
||||
"prettier": {
|
||||
"printWidth": 120,
|
||||
|
@ -100,6 +107,10 @@
|
|||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"jsxSingleQuote": true,
|
||||
"bracketSpacing": false
|
||||
"bracketSpacing": false,
|
||||
"bracketSameLine": true,
|
||||
"trailingComma": "all",
|
||||
"arrowParens": "always",
|
||||
"quoteProps": "consistent"
|
||||
}
|
||||
}
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -6,7 +6,7 @@ import terser from '@rollup/plugin-terser'
|
|||
|
||||
const production = process.env.NODE_ENV == 'production'
|
||||
|
||||
export default <RollupOptions>{
|
||||
export default {
|
||||
input: ['src/index.ts', 'src/server.ts'],
|
||||
output: {
|
||||
dir: 'build',
|
||||
|
@ -21,4 +21,4 @@ export default <RollupOptions>{
|
|||
production && terser(),
|
||||
].filter(Boolean),
|
||||
external: ['vscode'],
|
||||
}
|
||||
} as RollupOptions
|
||||
|
|
|
@ -80,12 +80,12 @@ function bundle(debug: boolean) {
|
|||
npx('rollup'),
|
||||
'--config',
|
||||
'--configPlugin=typescript={module:"esnext"}',
|
||||
`--environment=NODE_ENV:${environment}`
|
||||
`--environment=NODE_ENV:${environment}`,
|
||||
)
|
||||
}
|
||||
|
||||
function addon(debug: boolean, arch: string) {
|
||||
const cflags = <string[]>[]
|
||||
const cflags = [] as string[]
|
||||
switch (os.platform()) {
|
||||
case 'linux':
|
||||
// TODO: not implemented
|
||||
|
@ -119,10 +119,10 @@ function compdb() {
|
|||
const file = 'compile_commands.json'
|
||||
chdir('addon')
|
||||
exec(npx('node-gyp'), 'configure', '--', '--format=compile_commands_json')
|
||||
copy(`Debug/${file}`, file)
|
||||
copy(`build/Debug/${file}`, file)
|
||||
remove('Debug')
|
||||
remove('Release')
|
||||
const data = JSON.parse(fs.readFileSync(file, {encoding: 'utf8'})) as {[key: string]: string}[]
|
||||
const data = JSON.parse(fs.readFileSync(file, {encoding: 'utf8'})) as Record<string, string>[]
|
||||
const fixes = [] as [RegExp, string][]
|
||||
switch (os.platform()) {
|
||||
case 'darwin':
|
||||
|
|
18
src/data.ts
18
src/data.ts
|
@ -21,7 +21,7 @@ export function targetFunctions(): string[] {
|
|||
}
|
||||
|
||||
export function targetVariables(target?: string): string[] {
|
||||
const groups = <string[]>(target ? data.targetGroups[target] || [] : Object.keys(data.groupVariables))
|
||||
const groups = target ? data.targetGroups[target] ?? [] : Object.keys(data.groupVariables)
|
||||
const variables = groups.flatMap((group) => data.groupVariables[group])
|
||||
return [...new Set(variables)]
|
||||
}
|
||||
|
@ -29,13 +29,13 @@ export function targetVariables(target?: string): string[] {
|
|||
export function functionDetail(name?: string): FunctionDetail {
|
||||
if (!name) return {}
|
||||
if (data.targetGroups[name]) return {isTarget: true}
|
||||
return data.functionDetail[name] || {}
|
||||
return data.functionDetail[name] ?? {}
|
||||
}
|
||||
|
||||
export function variableDetail(name?: string): VariableDetail {
|
||||
if (!name) return {}
|
||||
if (data.builtinVariables[name]) return {isBuiltin: true}
|
||||
return data.variableDetail[name] || {}
|
||||
return data.variableDetail[name] ?? {}
|
||||
}
|
||||
|
||||
const data = {
|
||||
|
@ -69,7 +69,7 @@ const data = {
|
|||
tool: true,
|
||||
toolchain: true,
|
||||
write_file: true,
|
||||
},
|
||||
} as Record<string, boolean>,
|
||||
builtinVariables: {
|
||||
current_cpu: true,
|
||||
current_os: true,
|
||||
|
@ -88,7 +88,7 @@ const data = {
|
|||
target_name: true,
|
||||
target_os: true,
|
||||
target_out_dir: true,
|
||||
},
|
||||
} as Record<string, boolean>,
|
||||
targetGroups: {
|
||||
action: ['action'],
|
||||
action_foreach: ['action'],
|
||||
|
@ -105,7 +105,7 @@ const data = {
|
|||
shared_library: ['general', 'deps', 'flags', 'configs', 'rust', 'rust_extra', 'swift'],
|
||||
source_set: ['general', 'deps', 'flags', 'configs'],
|
||||
static_library: ['general', 'deps', 'flags', 'configs', 'static', 'rust', 'swift'],
|
||||
},
|
||||
} as Record<string, string[]>,
|
||||
groupVariables: {
|
||||
general: [
|
||||
'check_includes',
|
||||
|
@ -191,7 +191,7 @@ const data = {
|
|||
rust: ['aliased_deps', 'crate_name', 'crate_root'],
|
||||
rust_extra: ['crate_type'],
|
||||
swift: ['bridge_header', 'module_name'],
|
||||
},
|
||||
} as Record<string, string[]>,
|
||||
functionDetail: {
|
||||
assert: {}, // (condition[, error])
|
||||
declare_args: {}, // () {}
|
||||
|
@ -222,7 +222,7 @@ const data = {
|
|||
tool: {}, // (type) {}
|
||||
toolchain: {}, // (name) {}
|
||||
write_file: {}, // (filename, data, output_conversion = "")
|
||||
} as {[key: string]: FunctionDetail},
|
||||
} as Record<string, FunctionDetail>,
|
||||
variableDetail: {
|
||||
aliased_deps: {},
|
||||
all_dependent_configs: {isInput: true, isLabel: true},
|
||||
|
@ -298,5 +298,5 @@ const data = {
|
|||
xcasset_compiler_flags: {},
|
||||
xcode_extra_attributes: {},
|
||||
xcode_test_application_name: {},
|
||||
} as {[key: string]: VariableDetail},
|
||||
} as Record<string, VariableDetail>,
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ export interface TestDocumentSymbol {
|
|||
children?: TestDocumentSymbol[]
|
||||
}
|
||||
|
||||
export type TestAnalyzeResultType = {
|
||||
export interface TestAnalyzeResultType {
|
||||
location: string
|
||||
root: string
|
||||
token: {
|
||||
|
|
|
@ -4,24 +4,24 @@ import * as testData from './gn.test.data'
|
|||
|
||||
const root = './addon/gn/examples/simple_build'
|
||||
|
||||
function testAnalyzeResultItem(res: gn.Context, data: testData.TestAnalyzeResultType) {
|
||||
expect(res.root).toEqual(root.replace('./', ''))
|
||||
function testAnalyzeResultItem(res: gn.Context | null, data: testData.TestAnalyzeResultType) {
|
||||
expect(res?.root).toEqual(root.replace('./', ''))
|
||||
|
||||
expect(res.token?.type).toEqual(data.token.type)
|
||||
expect(res.token?.value).toEqual(data.token.value)
|
||||
expect(res?.token?.type).toEqual(data.token.type)
|
||||
expect(res?.token?.value).toEqual(data.token.value)
|
||||
|
||||
const locationString = (location?: gn.Location) => `${location?.line}:${location?.column}`
|
||||
expect(locationString(res.token?.range.begin)).toEqual(data.token.range.begin)
|
||||
expect(locationString(res.token?.range.end)).toEqual(data.token.range.end)
|
||||
expect(locationString(res?.token?.range.begin)).toEqual(data.token.range.begin)
|
||||
expect(locationString(res?.token?.range.end)).toEqual(data.token.range.end)
|
||||
|
||||
expect(res.function).toEqual(data.function)
|
||||
expect(res.variable).toEqual(data.variable)
|
||||
expect(res?.function).toEqual(data.function)
|
||||
expect(res?.variable).toEqual(data.variable)
|
||||
}
|
||||
|
||||
function testGNAnalyze(rootPath: string, data: testData.TestAnalyzeResultType[]) {
|
||||
data.forEach((data) => {
|
||||
const args = (s: string) => [rootPath, ...s.split(':').map((it) => parseInt(it, 10))]
|
||||
const res: gn.Context = gn.analyze.apply(null, args(data.location))
|
||||
const args = (s: string) => [rootPath, ...s.split(':').map((it) => parseInt(it, 10))] as [string, number, number]
|
||||
const res = gn.analyze.apply(null, args(data.location))
|
||||
testAnalyzeResultItem(res, data)
|
||||
})
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ function matchDocumentSymbol(symbol: gn.GNDocumentSymbol | undefined, data: test
|
|||
}
|
||||
expect(symbol?.name).toEqual(data.name)
|
||||
expect(symbol?.kind).toEqual(data.kind)
|
||||
expect(symbol?.children?.length || 0).toEqual(data.children?.length || 0)
|
||||
expect(symbol?.children?.length ?? 0).toEqual(data.children?.length ?? 0)
|
||||
assertRange(symbol?.range)
|
||||
assertRange(symbol?.selectionRange)
|
||||
if (data.children) {
|
||||
|
@ -67,7 +67,7 @@ it('simple_build/build/toolchain/BUILD.gn', async () => {
|
|||
|
||||
testGNAnalyze(rootPath, testData.toolchainGNAnalyzeResult)
|
||||
let currentSymbols = gn.parse(rootPath, rootContent)?.symbols
|
||||
let testSymbol = <gn.GNDocumentSymbol | undefined>testData.toolchainGNPartialDocumentSymbolResult
|
||||
let testSymbol = testData.toolchainGNPartialDocumentSymbolResult as gn.GNDocumentSymbol | undefined
|
||||
while (testSymbol) {
|
||||
const symbol = currentSymbols?.find((it) => it.name === testSymbol?.name)
|
||||
expect(symbol).toBeTruthy()
|
||||
|
|
|
@ -50,7 +50,8 @@ export interface GNDocumentSymbol {
|
|||
children?: GNDocumentSymbol[]
|
||||
}
|
||||
|
||||
const addon = require(`../build/${os.platform()}-${os.arch()}.node`) // eslint-disable-line @typescript-eslint/no-var-requires
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const addon = require(`../build/${os.platform()}-${os.arch()}.node`) as Record<string, unknown>
|
||||
export const update = addon.update as (file: string, content: string) => null
|
||||
export const close = addon.close as (file: string) => null
|
||||
export const validate = addon.validate as (file: string) => Error | null
|
||||
|
|
|
@ -20,7 +20,7 @@ export async function activate(context: ExtensionContext) {
|
|||
},
|
||||
{
|
||||
documentSelector: [{language: 'gn'}],
|
||||
}
|
||||
},
|
||||
)
|
||||
await client.start()
|
||||
}
|
||||
|
|
|
@ -27,21 +27,21 @@ connection.onInitialize(() => {
|
|||
}
|
||||
})
|
||||
|
||||
documents.onDidChangeContent((event) => {
|
||||
documents.onDidChangeContent(async (event) => {
|
||||
const uri = event.document.uri
|
||||
const file = URI.parse(uri).fsPath
|
||||
const uris = files.get(file) || new Set()
|
||||
const uris = files.get(file) ?? new Set()
|
||||
uris.add(uri)
|
||||
files.set(file, uris)
|
||||
const content = event.document.getText()
|
||||
gn.update(file, content)
|
||||
connection.sendDiagnostics({
|
||||
await connection.sendDiagnostics({
|
||||
uri: uri,
|
||||
diagnostics: getDiagnostics(file),
|
||||
})
|
||||
})
|
||||
|
||||
documents.onDidClose((event) => {
|
||||
documents.onDidClose(async (event) => {
|
||||
const uri = event.document.uri
|
||||
const file = URI.parse(uri).fsPath
|
||||
const uris = files.get(file)
|
||||
|
@ -51,7 +51,7 @@ documents.onDidClose((event) => {
|
|||
}
|
||||
if (!files.has(file)) {
|
||||
gn.close(file)
|
||||
connection.sendDiagnostics({
|
||||
await connection.sendDiagnostics({
|
||||
uri: uri,
|
||||
diagnostics: [],
|
||||
})
|
||||
|
@ -116,11 +116,11 @@ function getRange(range: gn.Range): ls.Range {
|
|||
}
|
||||
|
||||
function getDiagnostics(file: string): ls.Diagnostic[] {
|
||||
const result = <ls.Diagnostic[]>[]
|
||||
const result = [] as ls.Diagnostic[]
|
||||
const error = gn.validate(file)
|
||||
if (error) {
|
||||
result.push({
|
||||
range: getRange(error.ranges[0] || {begin: error.location, end: null}),
|
||||
range: getRange(error.ranges[0] ?? {begin: error.location, end: null}),
|
||||
severity: ls.DiagnosticSeverity.Error,
|
||||
source: 'gnls',
|
||||
message: [error.message, error.help].join('\n').trim(),
|
||||
|
@ -132,10 +132,10 @@ function getDiagnostics(file: string): ls.Diagnostic[] {
|
|||
function getFunctionCompletion(name: string): ls.CompletionItem {
|
||||
const detail = data.functionDetail(name)
|
||||
const help = gn.help('function', name)
|
||||
const result = <ls.CompletionItem>{
|
||||
const result = {
|
||||
label: name,
|
||||
kind: detail.isTarget ? ls.CompletionItemKind.Class : ls.CompletionItemKind.Function,
|
||||
}
|
||||
} as ls.CompletionItem
|
||||
if (help) {
|
||||
result.detail = help.basic
|
||||
result.documentation = {
|
||||
|
@ -149,10 +149,10 @@ function getFunctionCompletion(name: string): ls.CompletionItem {
|
|||
function getVariableCompletion(name: string): ls.CompletionItem {
|
||||
const detail = data.variableDetail(name)
|
||||
const help = gn.help('variable', name)
|
||||
const result = <ls.CompletionItem>{
|
||||
const result = {
|
||||
label: name,
|
||||
kind: detail.isBuiltin ? ls.CompletionItemKind.Variable : ls.CompletionItemKind.Field,
|
||||
}
|
||||
} as ls.CompletionItem
|
||||
if (help) {
|
||||
result.detail = help.basic
|
||||
result.documentation = {
|
||||
|
@ -176,7 +176,7 @@ function getLabelCompletion(name: string): ls.CompletionItem {
|
|||
}
|
||||
|
||||
function getCompletions(file: string, line: number, column: number): ls.CompletionItem[] {
|
||||
const result = <ls.CompletionItem[]>[]
|
||||
const result = [] as ls.CompletionItem[]
|
||||
const context = gn.analyze(file, line, column)
|
||||
switch (context?.token?.type) {
|
||||
case 'literal': {
|
||||
|
@ -197,8 +197,8 @@ function getCompletions(file: string, line: number, column: number): ls.Completi
|
|||
const scope = gn.parse(filepath, content)
|
||||
scope?.declares.forEach((declare) => {
|
||||
const func = declare.function
|
||||
const arg0 = (declare.arguments[0] || '').replace(/^"|"$/g, '')
|
||||
const arg1 = (declare.arguments[1] || '').replace(/^"|"$/g, '')
|
||||
const arg0 = (declare.arguments[0] ?? '').replace(/^"|"$/g, '')
|
||||
const arg1 = (declare.arguments[1] ?? '').replace(/^"|"$/g, '')
|
||||
const target = func == 'target' ? arg0 : func
|
||||
const label = func == 'target' ? arg1 : arg0
|
||||
if (data.functionDetail(target).isTarget && label) {
|
||||
|
@ -228,7 +228,7 @@ function getCompletions(file: string, line: number, column: number): ls.Completi
|
|||
result.push(...data.builtinVariables().map(getVariableCompletion))
|
||||
if (context?.function) {
|
||||
const func = context.function.name
|
||||
const arg0 = (context.function.arguments[0] || '').replace(/^"|"$/g, '')
|
||||
const arg0 = (context.function.arguments[0] ?? '').replace(/^"|"$/g, '')
|
||||
const target = func == 'target' ? arg0 : func
|
||||
if (func == 'template') {
|
||||
result.push(...data.targetFunctions().map(getFunctionCompletion))
|
||||
|
@ -264,7 +264,7 @@ function getHover(file: string, line: number, column: number): ls.Hover | undefi
|
|||
}
|
||||
|
||||
function getDefinition(file: string, line: number, column: number): ls.DefinitionLink[] {
|
||||
const result = <ls.DefinitionLink[]>[]
|
||||
const result = [] as ls.DefinitionLink[]
|
||||
const context = gn.analyze(file, line, column)
|
||||
switch (context?.token?.type) {
|
||||
case 'literal': {
|
||||
|
@ -281,8 +281,8 @@ function getDefinition(file: string, line: number, column: number): ls.Definitio
|
|||
return {
|
||||
originSelectionRange: origin,
|
||||
targetUri: URI.file(filepath).toString(),
|
||||
targetRange: range || target,
|
||||
targetSelectionRange: range || target,
|
||||
targetRange: range ?? target,
|
||||
targetSelectionRange: range ?? target,
|
||||
}
|
||||
}
|
||||
)(getRange(context.token.range), {
|
||||
|
@ -300,8 +300,8 @@ function getDefinition(file: string, line: number, column: number): ls.Definitio
|
|||
const scope = gn.parse(filepath, content)
|
||||
const declare = scope?.declares.find((declare) => {
|
||||
const func = declare.function
|
||||
const arg0 = (declare.arguments[0] || '').replace(/^"|"$/g, '')
|
||||
const arg1 = (declare.arguments[1] || '').replace(/^"|"$/g, '')
|
||||
const arg0 = (declare.arguments[0] ?? '').replace(/^"|"$/g, '')
|
||||
const arg1 = (declare.arguments[1] ?? '').replace(/^"|"$/g, '')
|
||||
const label = func == 'target' ? arg1 : arg0
|
||||
return label == target
|
||||
})
|
||||
|
@ -318,7 +318,7 @@ function getDefinition(file: string, line: number, column: number): ls.Definitio
|
|||
}
|
||||
|
||||
function getFormatted(file: string, lines: number): ls.TextEdit[] {
|
||||
const result = <ls.TextEdit[]>[]
|
||||
const result = [] as ls.TextEdit[]
|
||||
const code = gn.format(file)
|
||||
if (code) {
|
||||
result.push({
|
||||
|
@ -345,6 +345,6 @@ function getDocumentSymbol(file: string): ls.DocumentSymbol[] {
|
|||
}
|
||||
return result
|
||||
}
|
||||
const symbols = gn.parse(file)?.symbols || []
|
||||
const symbols = gn.parse(file)?.symbols ?? []
|
||||
return symbols.map(mapToDocumentSymbol)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
"target": "es2021",
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"strictNullChecks": true
|
||||
"strict": true,
|
||||
"noEmit": true
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче