Add exclude path for workspace symbols.
This commit is contained in:
parent
fded19fc8e
commit
f53599650d
13 changed files with 1611 additions and 247 deletions
1699
editors/vscode/package-lock.json
generated
1699
editors/vscode/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -7,9 +7,9 @@
|
|||
"type": "git",
|
||||
"url": "git://github.com/DanielGavin/ols.git"
|
||||
},
|
||||
"version": "0.1.30",
|
||||
"version": "0.1.33",
|
||||
"engines": {
|
||||
"vscode": "^1.66.0"
|
||||
"vscode": "^1.96.0"
|
||||
},
|
||||
"categories": [
|
||||
"Programming Languages"
|
||||
|
@ -146,14 +146,14 @@
|
|||
"@types/mocha": "^9.1.0",
|
||||
"@types/node": "~16.11.7",
|
||||
"@types/node-fetch": "^2.6.1",
|
||||
"@types/vscode": "~1.66.0",
|
||||
"@types/vscode": "^1.96.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
||||
"@typescript-eslint/parser": "^4.33.0",
|
||||
"eslint": "^7.32.0",
|
||||
"glob": "^7.2.0",
|
||||
"mocha": "^10.2.0",
|
||||
"typescript": "^4.6.2",
|
||||
"vsce": "^1.97.0",
|
||||
"@vscode/vsce": "^3.2.1",
|
||||
"vscode-test": "^1.6.1"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
|
@ -12,12 +12,13 @@ export function runDebugTest(ctx: Ctx): Cmd {
|
|||
const fn = debugConfig.function;
|
||||
const cwd = debugConfig.cwd;
|
||||
const pkg = path.basename(cwd);
|
||||
const importPkg = debugConfig.pkg;
|
||||
|
||||
var args = [];
|
||||
|
||||
args.push("test");
|
||||
args.push(cwd);
|
||||
args.push(`-test-name:${fn}`);
|
||||
args.push(".");
|
||||
args.push(`-define:ODIN_TEST_NAMES=${importPkg}.${fn}`);
|
||||
args.push("-debug");
|
||||
|
||||
for(var i = 0; i < ctx.config.collections.length; i++) {
|
||||
|
@ -36,20 +37,12 @@ export function runDebugTest(ctx: Ctx): Cmd {
|
|||
}
|
||||
|
||||
const odinExecution = execFile("odin", args, {cwd : workspaceFolder}, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
vscode.window.showErrorMessage(err.message);
|
||||
}
|
||||
});
|
||||
|
||||
odinExecution.on("exit", (code) => {
|
||||
|
||||
if(code !== 0) {
|
||||
throw Error("Odin test failed!");
|
||||
}
|
||||
|
||||
const possibleExecutables = [
|
||||
path.join(workspaceFolder, pkg),
|
||||
path.join(workspaceFolder, pkg) + '.bin'
|
||||
path.join(workspaceFolder, pkg) + '.exe'
|
||||
];
|
||||
|
||||
let promises : Promise<string | null>[] = [];
|
||||
|
@ -68,7 +61,7 @@ export function runDebugTest(ctx: Ctx): Cmd {
|
|||
results.forEach((r) => {
|
||||
if (r !== null && !found) {
|
||||
found = true;
|
||||
vscode.debug.startDebugging(undefined, getDebugConfiguration(ctx.config, r)).then(r => console.log("Result", r));
|
||||
vscode.debug.startDebugging(cwd, getDebugConfiguration(ctx.config, r)).then(r => console.log("Result", r));
|
||||
}
|
||||
});
|
||||
if (!found) {
|
||||
|
@ -84,13 +77,13 @@ export function runTest(ctx: Ctx): Cmd {
|
|||
return async(debugConfig: any) => {
|
||||
const fn = debugConfig.function;
|
||||
const cwd = debugConfig.cwd;
|
||||
const pkg = path.basename(cwd);
|
||||
const importPkg = debugConfig.pkg;
|
||||
|
||||
var args = [];
|
||||
|
||||
args.push("test");
|
||||
args.push(cwd);
|
||||
args.push(`-test-name:${fn}`);
|
||||
args.push(`-define:ODIN_TEST_NAMES=${importPkg}.${fn}`);
|
||||
|
||||
for(var i = 0; i < ctx.config.collections.length; i++) {
|
||||
const name = ctx.config.collections[i].name;
|
||||
|
|
|
@ -42,7 +42,7 @@ function getLldbDebugConfig(executable: string): vscode.DebugConfiguration {
|
|||
request: "launch",
|
||||
name: "test debug",
|
||||
program: executable,
|
||||
cwd: vscode.workspace.workspaceFolders?.[0].uri.path
|
||||
cwd: vscode.workspace.workspaceFolders?.[0].uri.fsPath
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,6 @@ function getCppvsDebugConfig(executable: string): vscode.DebugConfiguration {
|
|||
request: "launch",
|
||||
name: "test debug",
|
||||
program: executable,
|
||||
cwd: vscode.workspace.workspaceFolders?.[0].uri.path
|
||||
cwd: vscode.workspace.workspaceFolders?.[0].uri.fsPath
|
||||
};
|
||||
}
|
|
@ -53,29 +53,38 @@ export class RunnableCodeLensProvider implements CodeLensProvider {
|
|||
const text = doc.getText();
|
||||
const reTest = /\@\(?test\)?/g;
|
||||
const reFnTest = /\s*\w+\s*::\s*proc\s*\s*\(/g;
|
||||
const rePackageName = /package\s+\w+/g;
|
||||
|
||||
var testMatch: RegExpExecArray | null = null;
|
||||
|
||||
let lenses: CodeLens[] = [];
|
||||
while ((testMatch = reTest.exec(text)) !== null) {
|
||||
|
||||
reFnTest.lastIndex = reTest.lastIndex;
|
||||
const match = reFnTest.exec(text);
|
||||
const fnMatch = reFnTest.exec(text);
|
||||
|
||||
if (match === null) {
|
||||
if (fnMatch === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const fn = match[0].split(":")[0];
|
||||
const pkgMatch = rePackageName.exec(text);
|
||||
|
||||
if (pkgMatch === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const fn = fnMatch[0].split(":")[0];
|
||||
const pkg = pkgMatch[0].split(" ")[1];
|
||||
|
||||
if (fn && fn[0]) {
|
||||
|
||||
const debugCodelens = this.makeDebugLens(reTest.lastIndex, testMatch[0].length, fn.trim(), doc);
|
||||
const debugCodelens = this.makeDebugLens(reTest.lastIndex, testMatch[0].length, pkg, fn.trim(), doc);
|
||||
|
||||
if (debugCodelens !== undefined) {
|
||||
lenses.push(debugCodelens);
|
||||
}
|
||||
|
||||
const runCodelens = this.makeRunLens(reTest.lastIndex, testMatch[0].length, fn.trim(), doc);
|
||||
const runCodelens = this.makeRunLens(reTest.lastIndex, testMatch[0].length, pkg, fn.trim(), doc);
|
||||
|
||||
if (runCodelens !== undefined) {
|
||||
lenses.push(runCodelens);
|
||||
|
@ -88,7 +97,7 @@ export class RunnableCodeLensProvider implements CodeLensProvider {
|
|||
return lenses;
|
||||
}
|
||||
|
||||
private makeDebugLens(index: number, length: number, fn: string, doc: TextDocument) {
|
||||
private makeDebugLens(index: number, length: number, pkg:string, fn: string, doc: TextDocument) {
|
||||
const startIdx = index - length;
|
||||
const start = doc.positionAt(startIdx);
|
||||
const end = doc.positionAt(index);
|
||||
|
@ -100,13 +109,14 @@ export class RunnableCodeLensProvider implements CodeLensProvider {
|
|||
tooltip: "Debug",
|
||||
arguments: [{
|
||||
function: fn,
|
||||
cwd: path.dirname(doc.uri.fsPath)
|
||||
cwd: path.dirname(doc.uri.fsPath),
|
||||
pkg: pkg
|
||||
}]
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private makeRunLens(index: number, length: number, fn: string, doc: TextDocument): any | undefined {
|
||||
private makeRunLens(index: number, length: number, pkg: string, fn: string, doc: TextDocument): any | undefined {
|
||||
const startIdx = index - length;
|
||||
const start = doc.positionAt(startIdx);
|
||||
const end = doc.positionAt(index);
|
||||
|
@ -118,7 +128,8 @@ export class RunnableCodeLensProvider implements CodeLensProvider {
|
|||
tooltip: "Run",
|
||||
arguments: [{
|
||||
function: fn,
|
||||
cwd: path.dirname(doc.uri.fsPath)
|
||||
cwd: path.dirname(doc.uri.fsPath),
|
||||
pkg: pkg
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
|
|
@ -103,6 +103,13 @@
|
|||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"workspace_exclude_path": {
|
||||
"type": "array",
|
||||
"description": "List of paths that will be exldued from workspace symbol searches.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["name", "checker_path"],
|
||||
|
|
6
package-lock.json
generated
Normal file
6
package-lock.json
generated
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "ols",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {}
|
||||
}
|
|
@ -5,6 +5,7 @@ ConfigProfile :: struct {
|
|||
name: string,
|
||||
checker_path: [dynamic]string,
|
||||
defines: map[string]string,
|
||||
exclude_path: [dynamic]string,
|
||||
}
|
||||
|
||||
Config :: struct {
|
||||
|
|
|
@ -172,7 +172,13 @@ setup_index :: proc() {
|
|||
|
||||
dir_exe := common.get_executable_path(context.temp_allocator)
|
||||
|
||||
try_build_package(path.join({dir_exe, "builtin"}, context.temp_allocator))
|
||||
builtin_path := path.join({dir_exe, "builtin"}, context.temp_allocator)
|
||||
|
||||
if !os.exists(builtin_path) {
|
||||
log.error("Failed to find the builtin folder at %v", builtin_path)
|
||||
}
|
||||
|
||||
try_build_package(builtin_path)
|
||||
}
|
||||
|
||||
free_index :: proc() {
|
||||
|
|
|
@ -1443,6 +1443,7 @@ get_identifier_completion :: proc(
|
|||
insertText = result.snippet.insert,
|
||||
kind = .Snippet,
|
||||
detail = result.snippet.detail,
|
||||
documentation = result.doc,
|
||||
insertTextFormat = .Snippet,
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ memory_index_fuzzy_search :: proc(index: ^MemoryIndex, name: string, pkgs: []str
|
|||
|
||||
fuzzy_matcher := common.make_fuzzy_matcher(name)
|
||||
|
||||
top := 20
|
||||
top := 100
|
||||
|
||||
for pkg in pkgs {
|
||||
if pkg, ok := index.collection.packages[pkg]; ok {
|
||||
|
|
|
@ -399,15 +399,13 @@ read_ols_initialize_options :: proc(config: ^common.Config, ols_config: OlsConfi
|
|||
for profile in ols_config.profiles {
|
||||
if ols_config.profile == profile.name {
|
||||
config.profile.checker_path = make([dynamic]string, len(profile.checker_path))
|
||||
config.profile.exclude_path = make([dynamic]string, len(profile.exclude_path))
|
||||
|
||||
if filepath.is_abs(ols_config.profile) {
|
||||
for checker_path, i in profile.checker_path {
|
||||
config.profile.checker_path[i] = strings.clone(checker_path)
|
||||
}
|
||||
} else {
|
||||
for checker_path, i in profile.checker_path {
|
||||
config.profile.checker_path[i] = path.join(elems = {uri.path, checker_path})
|
||||
}
|
||||
for checker_path, i in profile.checker_path {
|
||||
config.profile.checker_path[i] = path.join(elems = {uri.path, checker_path})
|
||||
}
|
||||
for exclude_path, i in profile.exclude_path {
|
||||
config.profile.exclude_path[i] = path.join(elems = {uri.path, exclude_path})
|
||||
}
|
||||
|
||||
config.profile.os = strings.clone(profile.os)
|
||||
|
|
|
@ -5,34 +5,32 @@ import "core:fmt"
|
|||
import "core:log"
|
||||
import "core:os"
|
||||
import "core:path/filepath"
|
||||
import "core:strings"
|
||||
|
||||
import "src:common"
|
||||
|
||||
dir_blacklist :: []string{"node_modules", ".git"}
|
||||
|
||||
@(private)
|
||||
walk_dir :: proc(
|
||||
info: os.File_Info,
|
||||
in_err: os.Errno,
|
||||
user_data: rawptr,
|
||||
) -> (
|
||||
err: os.Error,
|
||||
skip_dir: bool,
|
||||
) {
|
||||
walk_dir :: proc(info: os.File_Info, in_err: os.Errno, user_data: rawptr) -> (err: os.Error, skip_dir: bool) {
|
||||
pkgs := cast(^[dynamic]string)user_data
|
||||
|
||||
if info.is_dir {
|
||||
dir, _ := filepath.to_slash(info.fullpath, context.temp_allocator)
|
||||
dir_name := filepath.base(dir)
|
||||
|
||||
for blacklist in dir_blacklist {
|
||||
if blacklist == dir_name {
|
||||
return nil, true
|
||||
}
|
||||
}
|
||||
append(pkgs, dir)
|
||||
}
|
||||
|
||||
return nil, false
|
||||
}
|
||||
|
||||
get_workspace_symbols :: proc(
|
||||
query: string,
|
||||
) -> (
|
||||
workspace_symbols: []WorkspaceSymbol,
|
||||
ok: bool,
|
||||
) {
|
||||
get_workspace_symbols :: proc(query: string) -> (workspace_symbols: []WorkspaceSymbol, ok: bool) {
|
||||
workspace := common.config.workspace_folders[0]
|
||||
uri := common.parse_uri(workspace.uri, context.temp_allocator) or_return
|
||||
pkgs := make([dynamic]string, 0, context.temp_allocator)
|
||||
|
@ -40,26 +38,40 @@ get_workspace_symbols :: proc(
|
|||
|
||||
filepath.walk(uri.path, walk_dir, &pkgs)
|
||||
|
||||
for pkg in pkgs {
|
||||
matches, err := filepath.glob(
|
||||
fmt.tprintf("%v/*.odin", pkg),
|
||||
context.temp_allocator,
|
||||
)
|
||||
log.error(pkgs)
|
||||
|
||||
_pkg: for pkg in pkgs {
|
||||
matches, err := filepath.glob(fmt.tprintf("%v/*.odin", pkg), context.temp_allocator)
|
||||
|
||||
if len(matches) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
for exclude_path in common.config.profile.exclude_path {
|
||||
exclude_forward, _ := filepath.to_slash(exclude_path, context.temp_allocator)
|
||||
|
||||
if exclude_forward[len(exclude_forward) - 2:] == "**" {
|
||||
lower_pkg := strings.to_lower(pkg)
|
||||
lower_exclude := strings.to_lower(exclude_forward[:len(exclude_forward) - 3])
|
||||
if strings.contains(lower_pkg, lower_exclude) {
|
||||
continue _pkg
|
||||
}
|
||||
} else {
|
||||
lower_pkg := strings.to_lower(pkg)
|
||||
lower_exclude := strings.to_lower(exclude_forward)
|
||||
if lower_pkg == lower_exclude {
|
||||
continue _pkg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try_build_package(pkg)
|
||||
|
||||
if results, ok := fuzzy_search(query, {pkg}); ok {
|
||||
for result in results {
|
||||
symbol := WorkspaceSymbol {
|
||||
name = result.symbol.name,
|
||||
location = {
|
||||
range = result.symbol.range,
|
||||
uri = result.symbol.uri,
|
||||
},
|
||||
location = {range = result.symbol.range, uri = result.symbol.uri},
|
||||
kind = symbol_kind_to_type(result.symbol.type),
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue