Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
Provide support for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
haiyangToAI committed Apr 4, 2024
1 parent dd21255 commit bbf82a8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
6 changes: 1 addition & 5 deletions client/src/needsExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,7 @@ export class NeedsExplorerProvider implements vscode.TreeDataProvider<vscode.Tre
let need_doc_path: string;
const needs_per_doc: NeedsPerDoc = {};
Object.values(needs_objects).forEach((nd) => {
if (curr_src_dir.endsWith('/')) {
need_doc_path = curr_src_dir + nd.docname + nd.doctype;
} else {
need_doc_path = curr_src_dir + '/' + nd.docname + nd.doctype;
}
need_doc_path = path.join(curr_src_dir, nd.docname, nd.doctype);

if (all_files_path.indexOf(need_doc_path) === -1) {
all_files_path.push(need_doc_path);
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Changelog

Under development

* Support for windows.

0.3.1
-----

Expand Down
36 changes: 19 additions & 17 deletions server/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

import fs = require('fs');
import fs_path = require('path');
import url = require('url');

import {
createConnection,
Expand Down Expand Up @@ -107,7 +109,7 @@ interface WsConfigs {

connection.onInitialize((params: InitializeParams) => {
if (params.workspaceFolders) {
workspace_folder_uri = params.workspaceFolders[0].uri;
workspace_folder_uri = url.fileURLToPath(params.workspaceFolders[0].uri);
} else {
workspace_folder_uri = '';
}
Expand Down Expand Up @@ -237,18 +239,16 @@ function check_wk_confs(configs: WsConfigs) {

// Get workspace settings
async function get_wk_conf_settings() {
const cal_wk_folder_uri: string = workspace_folder_uri.replace('file://', '');

// Get configuration of sphinx-needs.needsJson
let needs_json_path = '';
await connection.workspace.getConfiguration('sphinx-needs.needsJson').then((value) => {
needs_json_path = value.replace('${workspaceFolder}', cal_wk_folder_uri);
needs_json_path = value.replace('${workspaceFolder}', workspace_folder_uri);
});

// Get configuration of sphinx-needs.srcDir
let doc_src_dir = '';
await connection.workspace.getConfiguration('sphinx-needs.srcDir').then((value) => {
doc_src_dir = value.replace('${workspaceFolder}', cal_wk_folder_uri);
doc_src_dir = value.replace('${workspaceFolder}', workspace_folder_uri);
});

// Get configuration of sphinx-needs.loggingLevel
Expand All @@ -262,8 +262,8 @@ async function get_wk_conf_settings() {
await connection.workspace.getConfiguration('sphinx-needs.folders').then((value) => {
value.forEach((conf: DocConf) => {
wk_folders.push({
needsJson: conf.needsJson.replace('${workspaceFolder}', cal_wk_folder_uri),
srcDir: conf.srcDir.replace('${workspaceFolder}', cal_wk_folder_uri)
needsJson: conf.needsJson.replace('${workspaceFolder}', workspace_folder_uri),
srcDir: conf.srcDir.replace('${workspaceFolder}', workspace_folder_uri)
});
});
});
Expand Down Expand Up @@ -324,15 +324,15 @@ connection.onDidChangeWatchedFiles((_change) => {
let needs_json_file_changes: FileEvent | undefined;
const changed_files = _change.changes;
changed_files.forEach((changed_file) => {
const changed_file_uri = changed_file.uri.replace('file://', '');
const changed_file_uri = url.fileURLToPath(changed_file.uri);
if (Object.keys(needs_infos).indexOf(changed_file_uri) >= 0) {
needs_json_file_changes = changed_file;
}
});

// Needs Json file changed
if (needs_json_file_changes) {
const changed_needs_json = needs_json_file_changes.uri.replace('file://', '');
const changed_needs_json = url.fileURLToPath(needs_json_file_changes.uri);
// Check file change type
if (needs_json_file_changes.type === 1) {
// Usecase: configuration of NeedsJson file not in sync with needs json file name, user changed file name to sync
Expand Down Expand Up @@ -432,8 +432,8 @@ function load_needs_info_from_json(given_needs_json_path: string): NeedsTypesDoc
}
});
}
if (!curr_src_dir.endsWith('/')) {
curr_src_dir = curr_src_dir + '/';
if (!curr_src_dir.endsWith(fs_path.sep)) {
curr_src_dir = curr_src_dir + fs_path.sep;
}

// Initialize needs_types_docs_info
Expand Down Expand Up @@ -580,11 +580,13 @@ function complete_doc_path(docs: string[], doc_pattern: string): CompletionItem[

// At least two paths found, need to check if path contains folder and subfolder
const cnt_path_sep: number[] = [];
const regex = new RegExp(`[${fs_path.sep}]`, 'g');

found_paths.forEach((path) => {
cnt_path_sep.push((path.match(/[/]/g) || []).length);
cnt_path_sep.push((path.match(regex) || []).length);
});
const max_path_length: number = Math.max(...cnt_path_sep);
const curr_path_length: number = (doc_pattern.match(/[/]/g) || []).length;
const curr_path_length: number = (doc_pattern.match(regex) || []).length;

if (max_path_length === 0 && curr_path_length === 0) {
const sub_path_items: CompletionItem[] = [];
Expand All @@ -600,11 +602,11 @@ function complete_doc_path(docs: string[], doc_pattern: string): CompletionItem[

const sub_paths: string[] = [];
found_paths.forEach((path) => {
if ((path.match(/[/]/g) || []).length >= curr_path_length) {
if ((path.match(regex) || []).length >= curr_path_length) {
const new_sub_path = path
.split('/')
.split(fs_path.sep)
.slice(curr_path_length, curr_path_length + 1)
.join('/');
.join(fs_path.sep);

if (!sub_paths.includes(new_sub_path)) {
sub_paths.push(new_sub_path);
Expand Down Expand Up @@ -798,7 +800,7 @@ function get_curr_needs_info(params: TextDocumentPositionParams): NeedsTypesDocs
return needs_infos[wsConfigs.needsJson];
} else {
// Get current document file path
const curr_doc_uri = params.textDocument.uri.replace('file://', '');
const curr_doc_uri = url.fileURLToPath(params.textDocument.uri);
// Check and determine which needsJson infos to use
for (const [need_json, need_info] of Object.entries(needs_infos)) {
if (need_info?.all_files_abs_paths && need_info.all_files_abs_paths.indexOf(curr_doc_uri) >= 0) {
Expand Down

0 comments on commit bbf82a8

Please sign in to comment.